MCPcopy
hub / github.com/kopia/kopia / NewPersistentCache

Function NewPersistentCache

internal/cache/persistent_lru_cache.go:432–470  ·  view source on GitHub ↗

NewPersistentCache creates the persistent cache in the provided storage.

(ctx context.Context, description string, cacheStorage Storage, storageProtection cacheprot.StorageProtection, sweep SweepSettings, mr *metrics.Registry, timeNow func() time.Time)

Source from the content-addressed store, hash-verified

430
431// NewPersistentCache creates the persistent cache in the provided storage.
432func NewPersistentCache(ctx context.Context, description string, cacheStorage Storage, storageProtection cacheprot.StorageProtection, sweep SweepSettings, mr *metrics.Registry, timeNow func() time.Time) (*PersistentCache, error) {
433 if cacheStorage == nil {
434 return nil, nil
435 }
436
437 sweep = sweep.applyDefaults()
438
439 if storageProtection == nil {
440 storageProtection = cacheprot.NoProtection()
441 }
442
443 c := &PersistentCache{
444 cacheStorage: cacheStorage,
445 sweep: sweep,
446 description: description,
447 storageProtection: storageProtection,
448 metricsStruct: initMetricsStruct(mr, description),
449 listCache: newContentMetadataHeap(),
450 timeNow: timeNow,
451 lastCacheWarning: time.Time{},
452 }
453
454 if c.timeNow == nil {
455 c.timeNow = clock.Now
456 }
457
458 // verify that cache storage is functional by listing from it
459 if _, err := c.cacheStorage.GetMetadata(ctx, "test-blob"); err != nil && !errors.Is(err, blob.ErrBlobNotFound) {
460 return nil, errors.Wrapf(err, "unable to open %v", c.description)
461 }
462
463 releasable.Created("persistent-cache", c)
464
465 if err := c.initialScan(ctx); err != nil {
466 return nil, errors.Wrapf(err, "error during initial scan of %s", c.description)
467 }
468
469 return c, nil
470}

Calls 7

initialScanMethod · 0.95
NoProtectionFunction · 0.92
CreatedFunction · 0.92
newContentMetadataHeapFunction · 0.85
applyDefaultsMethod · 0.80
initMetricsStructFunction · 0.70
GetMetadataMethod · 0.65