Documentation
¶
Overview ¶
Package cache implements a caching strategy for byte slices.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Set = wire.NewSet( ProvideCache, )
Set is used by wire.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache implements a 3-level caching strategy.
func ProvideCache ¶
func ProvideCache( ctx context.Context, auto promauto.Factory, cfg *Config, logger *log.Logger, ) (*Cache, func(), error)
ProvideCache is called by wire.
func (*Cache) Get ¶
Get retrieves a value from the cache, providing it to val, which must be a *[]byte, *string, or encoding.BinaryUnmarshaler.
type Config ¶
type Config struct {
MaxMem int // Maximum in-memory cache size, in MB.
MaxDisk int // Maximum on-disk cache size, in MB.
Path string // The location of the disk cache.
// OnAdd is an optional callback that will be notified when new
// data is added to the cache.
OnAdd func(key string, data []byte)
// OnMiss provides an escape-hatch for retrieving cached data from
// other stores. Any non-nil error may be returned to indicate a
// cache miss.
OnMiss func(key string) ([]byte, error)
}
Config provides knobs for the cache.
Click to show internal directories.
Click to hide internal directories.