Documentation ¶
Overview ¶
Package lrucache provides reference-count-aware lru cache.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct { // OnEvicted optionally specifies a callback function to be // executed when an entry is purged from the cache. OnEvicted func(key string, value interface{}) // contains filtered or unexported fields }
Cache is "groupcache/lru"-like cache. The difference is that "groupcache/lru" immediately finalizes theevicted contents using OnEvicted callback but our version strictly tracks the reference counts of contents and calls OnEvicted when nobody refers to the evicted contents.
func (*Cache) Add ¶
func (c *Cache) Add(key string, value interface{}) (cachedValue interface{}, done func(), added bool)
Add adds object to the cache and returns the cached contents with incrementing the reference count. If the specified content already exists in the cache, this sets `added` to false and returns "already cached" content (i.e. doesn't replace the content with the new one). Client must call `done` callback to decrease the counter when the value will no longer be used.