Documentation
¶
Overview ¶
Package storage implements storage providers for the cache server.
Index ¶
- Variables
- type ChainStorageProvider
- func (sp *ChainStorageProvider) CacheHits() *metrics.CacheHits
- func (sp *ChainStorageProvider) Configure() error
- func (sp *ChainStorageProvider) Get(ctx context.Context, key *types.CacheKey) (object *types.CacheObject, err error)
- func (sp *ChainStorageProvider) Location() types.StorageLocation
- func (sp *ChainStorageProvider) Put(ctx context.Context, key *types.CacheKey, object *types.CacheObject) error
- func (sp *ChainStorageProvider) Query(ctx context.Context, keys []*types.CacheKey) ([]*types.CacheObjectMeta, error)
- func (sp *ChainStorageProvider) UsageInfo() *metrics.CacheUsage
- type ExpirationEntry
- type ExpirationHeap
- type ExpirationNotifier
- func (e *ExpirationNotifier) Add(hash string, expirationDate time.Time)
- func (e *ExpirationNotifier) ForceExpiration() error
- func (e *ExpirationNotifier) Monitor(ctx context.Context)
- func (e *ExpirationNotifier) NextExpiration() (string, time.Time)
- func (e *ExpirationNotifier) Notify() <-chan string
- func (e *ExpirationNotifier) WaitAll(ctx context.Context)
- func (e *ExpirationNotifier) WaitOne(ctx context.Context)
- type LocalStorageProvider
- func (p *LocalStorageProvider) CacheHits() *metrics.CacheHits
- func (p *LocalStorageProvider) Configure() error
- func (p *LocalStorageProvider) DeleteObjectsClosestToExpiration()
- func (p *LocalStorageProvider) Get(ctx context.Context, key *types.CacheKey) (*types.CacheObject, error)
- func (p *LocalStorageProvider) Location() types.StorageLocation
- func (p *LocalStorageProvider) Put(ctx context.Context, key *types.CacheKey, object *types.CacheObject) error
- func (p *LocalStorageProvider) Query(ctx context.Context, keys []*types.CacheKey) ([]*types.CacheObjectMeta, error)
- func (p *LocalStorageProvider) UsageInfo() *metrics.CacheUsage
- type S3StorageProvider
- func (sp *S3StorageProvider) CacheHits() *metrics.CacheHits
- func (sp *S3StorageProvider) Configure() (err error)
- func (sp *S3StorageProvider) Get(ctx context.Context, key *types.CacheKey) (*types.CacheObject, error)
- func (*S3StorageProvider) Location() types.StorageLocation
- func (sp *S3StorageProvider) Put(ctx context.Context, key *types.CacheKey, object *types.CacheObject) error
- func (sp *S3StorageProvider) Query(ctx context.Context, keys []*types.CacheKey) ([]*types.CacheObjectMeta, error)
- func (sp *S3StorageProvider) UsageInfo() *metrics.CacheUsage
- type StorageProvider
- func NewChainStorageProvider(ctx context.Context, providers ...StorageProvider) StorageProvider
- func NewLocalStorageProvider(ctx context.Context, cfg config.LocalStorageSpec) StorageProvider
- func NewS3StorageProvider(ctx context.Context, cfg config.RemoteStorageSpec) StorageProvider
- func NewVolatileStorageProvider(ctx context.Context, cfg config.VolatileStorageSpec) StorageProvider
- type VolatileStorageProvider
- func (sp *VolatileStorageProvider) CacheHits() *metrics.CacheHits
- func (sp *VolatileStorageProvider) Configure() error
- func (sp *VolatileStorageProvider) Get(ctx context.Context, key *types.CacheKey) (*types.CacheObject, error)
- func (sp *VolatileStorageProvider) Location() types.StorageLocation
- func (sp *VolatileStorageProvider) Put(ctx context.Context, key *types.CacheKey, object *types.CacheObject) error
- func (sp *VolatileStorageProvider) Query(ctx context.Context, keys []*types.CacheKey) ([]*types.CacheObjectMeta, error)
- func (sp *VolatileStorageProvider) UsageInfo() *metrics.CacheUsage
Constants ¶
This section is empty.
Variables ¶
var ConfigurationError = errors.New("Configuration Error")
var ForceExpirationFailedErr = errors.New("failed to force expiration of current object")
var S3StorageError = errors.New("S3 Storage Error")
Functions ¶
This section is empty.
Types ¶
type ChainStorageProvider ¶
type ChainStorageProvider struct {
// contains filtered or unexported fields
}
ChainStorageProvider is a chained/layered storage provider which queries one or more other storage providers as to increase performance when available. It is assumed that the provider list is sorted in order from fastest to slowest.
func (*ChainStorageProvider) CacheHits ¶
func (sp *ChainStorageProvider) CacheHits() *metrics.CacheHits
func (*ChainStorageProvider) Configure ¶
func (sp *ChainStorageProvider) Configure() error
func (*ChainStorageProvider) Get ¶
func (sp *ChainStorageProvider) Get( ctx context.Context, key *types.CacheKey, ) (object *types.CacheObject, err error)
func (*ChainStorageProvider) Location ¶
func (sp *ChainStorageProvider) Location() types.StorageLocation
func (*ChainStorageProvider) Put ¶
func (sp *ChainStorageProvider) Put( ctx context.Context, key *types.CacheKey, object *types.CacheObject, ) error
func (*ChainStorageProvider) Query ¶
func (sp *ChainStorageProvider) Query( ctx context.Context, keys []*types.CacheKey, ) ([]*types.CacheObjectMeta, error)
func (*ChainStorageProvider) UsageInfo ¶
func (sp *ChainStorageProvider) UsageInfo() *metrics.CacheUsage
type ExpirationEntry ¶
ExpirationEntry is an entry in the ExpirationHeap.
type ExpirationHeap ¶
type ExpirationHeap struct {
// contains filtered or unexported fields
}
ExpirationHeap implements a heap that stores the expiration dates of objects. The heap is indexed by the hash of the object. The heap is thread-safe.
func NewExpirationHeap ¶
func NewExpirationHeap() *ExpirationHeap
NewExpirationHeap creates a new ExpirationHeap.
func (*ExpirationHeap) Len ¶
func (h *ExpirationHeap) Len() int
Len returns the number of objects in the heap.
func (*ExpirationHeap) Peek ¶
func (h *ExpirationHeap) Peek() (string, time.Time)
Peek returns the next object in the heap.
func (*ExpirationHeap) Pop ¶
func (h *ExpirationHeap) Pop() *ExpirationEntry
Push adds a new object to the heap.
func (*ExpirationHeap) Push ¶
func (h *ExpirationHeap) Push(hash string, expirationDate time.Time)
Push adds a new object to the heap.
func (*ExpirationHeap) UnderlyingArray ¶
func (h *ExpirationHeap) UnderlyingArray() []*ExpirationEntry
UnderlyingArray returns a copy of the underlying array of the heap. This function should only be used for testing.
type ExpirationNotifier ¶
type ExpirationNotifier struct {
// contains filtered or unexported fields
}
ExpirationNotifier provides an efficient way to monitor the expiration of many objects. It stores expiration dates of objects in a binary heap and only waits for the next expiration event. It is used by the localStorageMonitor to monitor the expiration of objects.
func NewExpirationNotifier ¶
func NewExpirationNotifier() *ExpirationNotifier
func (*ExpirationNotifier) Add ¶
func (e *ExpirationNotifier) Add(hash string, expirationDate time.Time)
func (*ExpirationNotifier) ForceExpiration ¶
func (e *ExpirationNotifier) ForceExpiration() error
func (*ExpirationNotifier) Monitor ¶
func (e *ExpirationNotifier) Monitor(ctx context.Context)
func (*ExpirationNotifier) NextExpiration ¶
func (e *ExpirationNotifier) NextExpiration() (string, time.Time)
func (*ExpirationNotifier) Notify ¶
func (e *ExpirationNotifier) Notify() <-chan string
func (*ExpirationNotifier) WaitAll ¶
func (e *ExpirationNotifier) WaitAll(ctx context.Context)
func (*ExpirationNotifier) WaitOne ¶
func (e *ExpirationNotifier) WaitOne(ctx context.Context)
type LocalStorageProvider ¶
type LocalStorageProvider struct {
// contains filtered or unexported fields
}
func (*LocalStorageProvider) CacheHits ¶
func (p *LocalStorageProvider) CacheHits() *metrics.CacheHits
func (*LocalStorageProvider) Configure ¶
func (p *LocalStorageProvider) Configure() error
func (*LocalStorageProvider) DeleteObjectsClosestToExpiration ¶
func (p *LocalStorageProvider) DeleteObjectsClosestToExpiration()
func (*LocalStorageProvider) Get ¶
func (p *LocalStorageProvider) Get( ctx context.Context, key *types.CacheKey, ) (*types.CacheObject, error)
func (*LocalStorageProvider) Location ¶
func (p *LocalStorageProvider) Location() types.StorageLocation
func (*LocalStorageProvider) Put ¶
func (p *LocalStorageProvider) Put( ctx context.Context, key *types.CacheKey, object *types.CacheObject, ) error
func (*LocalStorageProvider) Query ¶
func (p *LocalStorageProvider) Query( ctx context.Context, keys []*types.CacheKey, ) ([]*types.CacheObjectMeta, error)
func (*LocalStorageProvider) UsageInfo ¶
func (p *LocalStorageProvider) UsageInfo() *metrics.CacheUsage
type S3StorageProvider ¶
type S3StorageProvider struct {
// contains filtered or unexported fields
}
func (*S3StorageProvider) CacheHits ¶
func (sp *S3StorageProvider) CacheHits() *metrics.CacheHits
func (*S3StorageProvider) Configure ¶
func (sp *S3StorageProvider) Configure() (err error)
func (*S3StorageProvider) Get ¶
func (sp *S3StorageProvider) Get( ctx context.Context, key *types.CacheKey, ) (*types.CacheObject, error)
func (*S3StorageProvider) Location ¶
func (*S3StorageProvider) Location() types.StorageLocation
func (*S3StorageProvider) Put ¶
func (sp *S3StorageProvider) Put( ctx context.Context, key *types.CacheKey, object *types.CacheObject, ) error
func (*S3StorageProvider) Query ¶
func (sp *S3StorageProvider) Query( ctx context.Context, keys []*types.CacheKey, ) ([]*types.CacheObjectMeta, error)
func (*S3StorageProvider) UsageInfo ¶
func (sp *S3StorageProvider) UsageInfo() *metrics.CacheUsage
type StorageProvider ¶
type StorageProvider interface { // Location should return the location kind of stored data. Location() types.StorageLocation // Configure should perform any necessary setup procedures that must be // completed prior to querying this storage provider. Configure() error // Put should store the given keyed object. Put(context.Context, *types.CacheKey, *types.CacheObject) error // Get should return the keyed object if it exists, or return // a relevant error if it does not exist. Get(context.Context, *types.CacheKey) (*types.CacheObject, error) // Query should return object metadata for each key in the provided // slice. If any key does not exist, the corresponding element in the // resulting slice should be nil. The length of the resulting slice // must match exactly with the length of the input slice. Query(context.Context, []*types.CacheKey) ([]*types.CacheObjectMeta, error) // UsageInfo should calculate and return usage information for the storage // provider. UsageInfo() *metrics.CacheUsage // CacheHits should return information about cache hits and misses. CacheHits() *metrics.CacheHits }
A StorageProvider represents an object capable of storing and retrieving cached data.
func NewChainStorageProvider ¶
func NewChainStorageProvider( ctx context.Context, providers ...StorageProvider, ) StorageProvider
NewChainStorageProvider creates a new ChainStorageProvider with the given storage providers, which should be sorted in order from fastest to slowest.
func NewLocalStorageProvider ¶
func NewLocalStorageProvider( ctx context.Context, cfg config.LocalStorageSpec, ) StorageProvider
func NewS3StorageProvider ¶
func NewS3StorageProvider( ctx context.Context, cfg config.RemoteStorageSpec, ) StorageProvider
func NewVolatileStorageProvider ¶
func NewVolatileStorageProvider( ctx context.Context, cfg config.VolatileStorageSpec, ) StorageProvider
type VolatileStorageProvider ¶
type VolatileStorageProvider struct {
// contains filtered or unexported fields
}
func (*VolatileStorageProvider) CacheHits ¶
func (sp *VolatileStorageProvider) CacheHits() *metrics.CacheHits
func (*VolatileStorageProvider) Configure ¶
func (sp *VolatileStorageProvider) Configure() error
func (*VolatileStorageProvider) Get ¶
func (sp *VolatileStorageProvider) Get( ctx context.Context, key *types.CacheKey, ) (*types.CacheObject, error)
func (*VolatileStorageProvider) Location ¶
func (sp *VolatileStorageProvider) Location() types.StorageLocation
func (*VolatileStorageProvider) Put ¶
func (sp *VolatileStorageProvider) Put( ctx context.Context, key *types.CacheKey, object *types.CacheObject, ) error
func (*VolatileStorageProvider) Query ¶
func (sp *VolatileStorageProvider) Query( ctx context.Context, keys []*types.CacheKey, ) ([]*types.CacheObjectMeta, error)
func (*VolatileStorageProvider) UsageInfo ¶
func (sp *VolatileStorageProvider) UsageInfo() *metrics.CacheUsage