lru package - github.com/golang/groupcache/lru - Go Packages (original) (raw)
Package lru implements an LRU cache.
This section is empty.
This section is empty.
This section is empty.
type Cache struct {
MaxEntries [int](/builtin#int)
OnEvicted func(key [Key](#Key), value interface{})}
Cache is an LRU cache. It is not safe for concurrent access.
func New(maxEntries int) *Cache
New creates a new Cache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.
func (c *Cache) Add(key Key, value interface{})
Add adds a value to the cache.
Clear purges all stored items from the cache.
func (c *Cache) Get(key Key) (value interface{}, ok bool)
Get looks up a key's value from the cache.
Len returns the number of items in the cache.
func (c *Cache) Remove(key Key)
Remove removes the provided key from the cache.
func (c *Cache) RemoveOldest()
RemoveOldest removes the oldest item from the cache.