MCPcopy
hub / github.com/kopia/kopia / NewManagerWithCache

Function NewManagerWithCache

repo/format/format_manager.go:386–420  ·  view source on GitHub ↗

NewManagerWithCache creates new format manager which automatically refreshes format blob on reads (in a blocking manner) and uses the provided cache.

(
	ctx context.Context,
	st blob.Storage,
	validDuration time.Duration,
	password string,
	timeNow func() time.Time,
	cache blobCache,
)

Source from the content-addressed store, hash-verified

384// NewManagerWithCache creates new format manager which automatically refreshes format blob on reads (in a blocking manner)
385// and uses the provided cache.
386func NewManagerWithCache(
387 ctx context.Context,
388 st blob.Storage,
389 validDuration time.Duration,
390 password string,
391 timeNow func() time.Time,
392 cache blobCache,
393) (*Manager, error) {
394 var ignoreCacheOnFirstRefresh bool
395
396 if validDuration < 0 {
397 // valid duration less than zero indicates we want to skip cache on first access
398 validDuration = DefaultRepositoryBlobCacheDuration
399 ignoreCacheOnFirstRefresh = true
400 }
401
402 if validDuration > DefaultRepositoryBlobCacheDuration {
403 log(ctx).Infof("repository format cache duration capped at %v", DefaultRepositoryBlobCacheDuration)
404
405 validDuration = DefaultRepositoryBlobCacheDuration
406 }
407
408 m := &Manager{
409 blobs: st,
410 validDuration: validDuration,
411 password: password,
412 cache: cache,
413 timeNow: timeNow,
414 ignoreCacheOnFirstRefresh: ignoreCacheOnFirstRefresh,
415 }
416
417 err := m.refresh(ctx)
418
419 return m, err
420}
421
422// ErrAlreadyInitialized indicates that repository has already been initialized.
423var ErrAlreadyInitialized = errors.New("repository already initialized")

Callers 7

TestFormatManagerFunction · 0.92
TestUpdateRetentionFunction · 0.92
TestChangePasswordFunction · 0.92
NewManagerFunction · 0.85

Calls 1

refreshMethod · 0.95

Tested by 6

TestFormatManagerFunction · 0.74
TestUpdateRetentionFunction · 0.74
TestChangePasswordFunction · 0.74