MCPcopy
hub / github.com/kopia/kopia / getPartial

Method getPartial

internal/cache/persistent_lru_cache.go:132–162  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
132func (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.
165func (c *PersistentCache) Put(ctx context.Context, key string, data gather.Bytes) {

Callers 4

getFullMethod · 0.95
PrefetchBlobMethod · 0.80

Calls 10

CloseMethod · 0.95
BytesMethod · 0.95
getPartialCacheHitMethod · 0.95
deleteInvalidBlobMethod · 0.95
IDTypeAlias · 0.92
NoProtectionFunction · 0.92
reportMalformedDataMethod · 0.80
reportMissBytesMethod · 0.80
GetBlobMethod · 0.65
VerifyMethod · 0.65

Tested by

no test coverage detected