MCPcopy
hub / github.com/kopia/kopia / NewContentCache

Function NewContentCache

internal/cache/content_cache.go:175–200  ·  view source on GitHub ↗

NewContentCache creates new content cache for data contents.

(ctx context.Context, st blob.Storage, opt Options, mr *metrics.Registry)

Source from the content-addressed store, hash-verified

173
174// NewContentCache creates new content cache for data contents.
175func NewContentCache(ctx context.Context, st blob.Storage, opt Options, mr *metrics.Registry) (ContentCache, error) {
176 cacheStorage := opt.Storage
177 if cacheStorage == nil {
178 if opt.BaseCacheDirectory == "" {
179 return passthroughContentCache{st}, nil
180 }
181
182 var err error
183
184 cacheStorage, err = NewStorageOrNil(ctx, opt.BaseCacheDirectory, opt.Sweep.MaxSizeBytes, opt.CacheSubDir)
185 if err != nil {
186 return nil, errors.Wrap(err, "error initializing cache storage")
187 }
188 }
189
190 pc, err := NewPersistentCache(ctx, opt.CacheSubDir, cacheStorage, cacheprot.ChecksumProtection(opt.HMACSecret), opt.Sweep, mr, opt.TimeNow)
191 if err != nil {
192 return nil, errors.Wrap(err, "unable to create base cache")
193 }
194
195 return &contentCacheImpl{
196 st: st,
197 pc: pc,
198 fetchFullBlobs: opt.FetchFullBlobs,
199 }, nil
200}

Calls 3

ChecksumProtectionFunction · 0.92
NewStorageOrNilFunction · 0.85
NewPersistentCacheFunction · 0.85

Tested by 11

newContentDataCacheFunction · 0.74
newContentMetadataCacheFunction · 0.74
verifyCacheExpirationFunction · 0.74
TestDiskContentCacheFunction · 0.74
TestCacheFailureToOpenFunction · 0.74
TestCacheFailureToWriteFunction · 0.74
TestCacheFailureToReadFunction · 0.74
TestContentCacheForDataFunction · 0.74