Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EvictCallback ¶
type EvictCallback func(key string, value interface{})
EvictCallback is a type for notifying applications when an item is scheduled for eviction from the Cache.
type LRU ¶
func NewLRUWithOptions ¶
NewLRUWithOptions creates a new LRU cache with the given options.
func (*LRU) CompareAndSwap ¶
func (c *LRU) CompareAndSwap(key string, oldValue, newValue interface{}) (itemInCache interface{}, replaced bool)
CompareAndSwap puts a new value associated with a given key if existing value matches oldValue. It returns itemInCache as the element in cache after the function is executed and replaced as true if value is replaced, false otherwise.
type Options ¶
type Options struct { // TTL controls the time-to-live for a given cache entry. Cache entries that // are older than the TTL will not be returned TTL time.Duration // InitialCapacity controls the initial capacity of the cache InitialCapacity int // OnEvict is an optional function called when an element is evicted. OnEvict EvictCallback // TimeNow is used to override the behavior of default time.Now(), e.g. in tests. TimeNow func() time.Time }
Options control the behavior of the cache
Click to show internal directories.
Click to hide internal directories.