Documentation ¶
Index ¶
- type Cache
- func (c *Cache) Add(key, value interface{}, weight uint) (evicted int)
- func (c *Cache) Contains(key interface{}) bool
- func (c *Cache) ContainsOrAdd(key, value interface{}, weight uint) (ok bool, evicted int)
- func (c *Cache) Get(key interface{}) (value interface{}, ok bool)
- func (c *Cache) GetOldest() (key interface{}, value interface{}, ok bool)
- func (c *Cache) Keys() []interface{}
- func (c *Cache) Len() int
- func (c *Cache) Peek(key interface{}) (value interface{}, ok bool)
- func (c *Cache) PeekOrAdd(key, value interface{}, weight uint) (previous interface{}, ok bool, evicted int)
- func (c *Cache) Purge()
- func (c *Cache) Remove(key interface{}) (present bool)
- func (c *Cache) RemoveOldest() (key interface{}, value interface{}, ok bool)
- func (c *Cache) Resize(maxWeight uint, maxSize int) (evicted int)
- func (c *Cache) Total() (weight uint, num int)
- func (c *Cache) Weight() uint
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(maxWeight uint, maxSize int, onEvicted func(key interface{}, value interface{})) (*Cache, error)
NewWithEvict constructs a fixed weight/size cache with the given eviction callback.
func (*Cache) Contains ¶
Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.
func (*Cache) ContainsOrAdd ¶
ContainsOrAdd checks if a key is in the cache without updating the recent-ness or deleting it for being stale, and if not, adds the value. Returns whether found and whether an eviction occurred.
func (*Cache) Keys ¶
func (c *Cache) Keys() []interface{}
Keys returns a slice of the keys in the cache, from oldest to newest.
func (*Cache) Peek ¶
Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
func (*Cache) PeekOrAdd ¶
func (c *Cache) PeekOrAdd(key, value interface{}, weight uint) (previous interface{}, ok bool, evicted int)
PeekOrAdd checks if a key is in the cache without updating the recent-ness or deleting it for being stale, and if not, adds the value. Returns whether found and whether an eviction occurred.
func (*Cache) RemoveOldest ¶
RemoveOldest removes the oldest item from the cache.