Documentation ¶
Overview ¶
Package cache implements durable on-disk cache with LRU expiration.
Index ¶
- Constants
- func BlobIDCacheKey(id blob.ID) string
- func ContentIDCacheKey(contentID string) string
- type ContentCache
- type Options
- type PersistentCache
- func (c *PersistentCache) CacheStorage() Storage
- func (c *PersistentCache) Close(ctx context.Context)
- func (c *PersistentCache) GetFetchingMutex(id blob.ID) *sync.RWMutex
- func (c *PersistentCache) GetFull(ctx context.Context, key string, output *gather.WriteBuffer) bool
- func (c *PersistentCache) GetOrLoad(ctx context.Context, key string, fetch func(output *gather.WriteBuffer) error, ...) error
- func (c *PersistentCache) GetPartial(ctx context.Context, key string, offset, length int64, ...) bool
- func (c *PersistentCache) Put(ctx context.Context, key string, data gather.Bytes)
- type Storage
- type SweepSettings
Constants ¶
const ( // DefaultTouchThreshold specifies the resolution of timestamps used to determine which cache items // to expire. This helps cache storage writes on frequently accessed items. DefaultTouchThreshold = 10 * time.Minute )
const DirMode = 0o700
DirMode is the directory mode for all caches.
Variables ¶
This section is empty.
Functions ¶
func BlobIDCacheKey ¶ added in v0.10.7
BlobIDCacheKey computes the cache key for the provided blob ID.
func ContentIDCacheKey ¶ added in v0.10.7
ContentIDCacheKey computes the cache key for the provided content ID.
Types ¶
type ContentCache ¶ added in v0.10.7
type ContentCache interface { Close(ctx context.Context) GetContent(ctx context.Context, contentID string, blobID blob.ID, offset, length int64, output *gather.WriteBuffer) error PrefetchBlob(ctx context.Context, blobID blob.ID) error CacheStorage() Storage }
ContentCache caches contents stored in pack blobs.
type Options ¶ added in v0.10.7
type Options struct { BaseCacheDirectory string CacheSubDir string Storage Storage // force particular storage, used for testing HMACSecret []byte FetchFullBlobs bool Sweep SweepSettings TimeNow func() time.Time }
Options encapsulates all content cache options.
type PersistentCache ¶
type PersistentCache struct {
// contains filtered or unexported fields
}
PersistentCache provides persistent on-disk cache.
func NewPersistentCache ¶
func NewPersistentCache(ctx context.Context, description string, cacheStorage Storage, storageProtection cacheprot.StorageProtection, sweep SweepSettings, mr *metrics.Registry, timeNow func() time.Time) (*PersistentCache, error)
NewPersistentCache creates the persistent cache in the provided storage.
func (*PersistentCache) CacheStorage ¶ added in v0.10.6
func (c *PersistentCache) CacheStorage() Storage
CacheStorage returns cache storage.
func (*PersistentCache) Close ¶
func (c *PersistentCache) Close(ctx context.Context)
Close closes the instance of persistent cache possibly waiting for at least one sweep to complete.
func (*PersistentCache) GetFetchingMutex ¶ added in v0.10.7
func (c *PersistentCache) GetFetchingMutex(id blob.ID) *sync.RWMutex
GetFetchingMutex returns a RWMutex used to lock a blob or content during loading.
func (*PersistentCache) GetFull ¶ added in v0.10.6
func (c *PersistentCache) GetFull(ctx context.Context, key string, output *gather.WriteBuffer) bool
GetFull fetches the contents of a full blob. Returns false if not found.
func (*PersistentCache) GetOrLoad ¶
func (c *PersistentCache) GetOrLoad(ctx context.Context, key string, fetch func(output *gather.WriteBuffer) error, output *gather.WriteBuffer) error
GetOrLoad is utility function gets the provided item from the cache or invokes the provided fetch function. The function also appends and verifies HMAC checksums using provided secret on all cached items to ensure data integrity.
func (*PersistentCache) GetPartial ¶ added in v0.10.6
func (c *PersistentCache) GetPartial(ctx context.Context, key string, offset, length int64, output *gather.WriteBuffer) bool
GetPartial fetches the contents of a cached blob when (length < 0) or a subset of it (when length >= 0). returns false if not found.