Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stoppable ¶
type Stoppable interface {
// Stop is the method called when an item is evicted from the cache.
Stop()
}
Stoppable is the interface that wraps a basic Stop method.
type TTL ¶
type TTL struct {
// contains filtered or unexported fields
}
TTL is a time-to-live cache. Entries added to it are automatically culled after a period of inactivity. When evicted from the cache, the entry's Stop() method will be called.
Example usage:
cache := cache.NewTTL() go cache.Start(stopCh) cachedValue := cache.Insert(key, value) cachedValue.Start() otherValue := cache.Get(otherKey) if otherValue != nil { ...use otherValue... } ...cachedValue times out and cachedValue.Stop() is called in a background goroutine...
func NewTTL ¶
func NewTTL() *TTL
NewTTL creates a new cache.TTL. Note that for the culling to occur, Start(stopCh) must be called.
cache := cache.NewTTL() go cache.Start(stopCh)
func (*TTL) DeleteIfPresent ¶
DeleteIfPresent deletes an entry from the cache if its value in the cache is equal to value.
func (*TTL) Get ¶
Get gets an item in the cache and extends its time to live. If the key is not present in the cache, nil is returned.
func (*TTL) Insert ¶
Insert inserts an item into the cache. If something is already stored with that key, then the existing stored value is returned. This is especially important if the value needs to be started, in which case the returned value must be started, not the input.
cachedValue := cache.Insert(key, value) // Note that cachedValue may either be value or something that was already in the cache. cachedValue.Start()