Documentation ¶
Overview ¶
This package provides a simple LRU cache. It is based on the LRU implementation in groupcache: https://github.com/golang/groupcache/tree/master/lru
Index ¶
- type Cache
- func (c *Cache) Add(key, value interface{})
- func (c *Cache) Get(key interface{}) (value interface{}, ok bool)
- func (c *Cache) Len() int
- func (c *Cache) OnRemove(f func(interface{}))
- func (c *Cache) Purge()
- func (c *Cache) Remove(key interface{})
- func (c *Cache) RemoveOldest()
- func (cache *Cache) ScheduleClear(d time.Duration)
- func (c *Cache) Update(key interface{}, f func(val interface{})) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a thread-safe fixed size LRU cache.
func (*Cache) OnRemove ¶
func (c *Cache) OnRemove(f func(interface{}))
Specify a function to run before deleting an item from the cache
func (*Cache) Remove ¶
func (c *Cache) Remove(key interface{})
Remove removes the provided key from the cache.
func (*Cache) RemoveOldest ¶
func (c *Cache) RemoveOldest()
RemoveOldest removes the oldest item from the cache.
func (*Cache) ScheduleClear ¶
Schedule routine purges. May be used to free up memory or ensure that the OnRemove function is called within a certain amount of time.
Click to show internal directories.
Click to hide internal directories.