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 int64, value simplelru.VersionedValue) simplelru.VersionedValue
- func (c *Cache) Contains(key int64) bool
- func (c *Cache) Get(key int64) (simplelru.VersionedValue, bool)
- func (c *Cache) Keys() []int64
- func (c *Cache) Len() int
- func (c *Cache) Peek(key int64) (simplelru.VersionedValue, bool)
- func (c *Cache) Purge()
- func (c *Cache) Remove(key int64)
- func (c *Cache) RemoveOldest()
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 NewWithEvict ¶
func NewWithEvict(size int, onEvicted func(key int64, value simplelru.VersionedValue)) (*Cache, error)
NewWithEvict constructs a fixed size cache with the given eviction callback.
func (*Cache) Add ¶
func (c *Cache) Add(key int64, value simplelru.VersionedValue) simplelru.VersionedValue
Add adds a value to the cache. Returns true if an eviction occurred.
func (*Cache) Contains ¶
Check if a key is in the cache, without updating the recent-ness or deleting it for being stale.
func (*Cache) Get ¶
func (c *Cache) Get(key int64) (simplelru.VersionedValue, bool)
Get looks up a key's value from the cache.
func (*Cache) Peek ¶
func (c *Cache) Peek(key int64) (simplelru.VersionedValue, bool)
Returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
func (*Cache) RemoveOldest ¶
func (c *Cache) RemoveOldest()
RemoveOldest removes the oldest item from the cache.