getPartial fetches the contents of a cached blob when (length < 0) or a subset of it (when length >= 0) and returns true if it is found.
(ctx context.Context, key string, offset, length int64, output *gather.WriteBuffer)
| 130 | // getPartial fetches the contents of a cached blob when (length < 0) or a subset |
| 131 | // of it (when length >= 0) and returns true if it is found. |
| 132 | func (c *PersistentCache) getPartial(ctx context.Context, key string, offset, length int64, output *gather.WriteBuffer) bool { |
| 133 | if c == nil { |
| 134 | return false |
| 135 | } |
| 136 | |
| 137 | var tmp gather.WriteBuffer |
| 138 | defer tmp.Close() |
| 139 | |
| 140 | if err := c.cacheStorage.GetBlob(ctx, blob.ID(key), offset, length, &tmp); err == nil { |
| 141 | sp := c.storageProtection |
| 142 | |
| 143 | if length >= 0 { |
| 144 | // do not perform integrity check on partial reads |
| 145 | sp = cacheprot.NoProtection() |
| 146 | } |
| 147 | |
| 148 | if err := sp.Verify(key, tmp.Bytes(), output); err == nil { |
| 149 | c.getPartialCacheHit(ctx, key, length, output) |
| 150 | |
| 151 | return true |
| 152 | } |
| 153 | |
| 154 | c.reportMalformedData() |
| 155 | c.deleteInvalidBlob(ctx, key) |
| 156 | } |
| 157 | |
| 158 | // cache miss |
| 159 | c.reportMissBytes(max(length, 0)) |
| 160 | |
| 161 | return false |
| 162 | } |
| 163 | |
| 164 | // Put adds the provided key-value pair to the cache. |
| 165 | func (c *PersistentCache) Put(ctx context.Context, key string, data gather.Bytes) { |
no test coverage detected