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, )
| 384 | // NewManagerWithCache creates new format manager which automatically refreshes format blob on reads (in a blocking manner) |
| 385 | // and uses the provided cache. |
| 386 | func 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. |
| 423 | var ErrAlreadyInitialized = errors.New("repository already initialized") |