NewContentCache creates new content cache for data contents.
(ctx context.Context, st blob.Storage, opt Options, mr *metrics.Registry)
| 173 | |
| 174 | // NewContentCache creates new content cache for data contents. |
| 175 | func 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 | } |