Documentation ¶
Overview ¶
Package cache provides a generic threadsafe expiring cache implementation that is capable of passing cache misses through to a lookup function.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClosed is returned from calls to the cache or in the event that the // Close() function has already been called. ErrClosed = errors.New("the cache is closing or already closed") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a threadsafe expiring cache that is capable of passing cache misses through to a lookup function.
func New ¶
New returns a new cache whose values survive for the given duration and are retrieved with the given lookup function.
func (*Cache) Close ¶
func (cache *Cache) Close()
Close will release any resources consumed by the cache and its contents. It will also prevent further use of the cache.
func (*Cache) Evict ¶
func (cache *Cache) Evict()
Evict will expuge all existing values from the cache. Outstanding lookups that are still pending will not be affected.
func (*Cache) Lookup ¶
func (cache *Cache) Lookup(ctx context.Context, key Key, tracker dfsr.Tracker) (value Value, err error)
Lookup returns the value for the given key if it exists in the cache and has not expired. If the cached value is missing or expired, a lookup will be performed.
If the cache has been closed then ErrClosed will be returned.
type Closer ¶
type Closer interface {
Close()
}
Closer is an interface that cache values may implement to be closed when their entries expire.