Documentation ¶
Index ¶
- type Cache
- func (c *Cache) Add(key, value interface{}) (evicted bool)
- func (c *Cache) Contains(key interface{}) bool
- func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evicted bool)
- func (c *Cache) Get(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) Purge()
- func (c *Cache) Remove(key interface{})
- func (c *Cache) RemoveOldest()
- type EvictCallback
- type UnLockCache
- func (c *UnLockCache) Add(key, value interface{}) (evicted bool)
- func (c *UnLockCache) Contains(key interface{}) (ok bool)
- func (c *UnLockCache) Get(key interface{}) (value interface{}, ok bool)
- func (c *UnLockCache) GetOldest() (key interface{}, value interface{}, ok bool)
- func (c *UnLockCache) Keys() []interface{}
- func (c *UnLockCache) Len() int
- func (c *UnLockCache) Peek(key interface{}) (value interface{}, ok bool)
- func (c *UnLockCache) Purge()
- func (c *UnLockCache) Remove(key interface{}) (present bool)
- func (c *UnLockCache) RemoveOldest() (key interface{}, value interface{}, ok 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 ulc cache.
func NewWithEvict ¶
NewWithEvict constructs a fixed 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) 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.
type EvictCallback ¶
type EvictCallback func(key interface{}, value interface{})
EvictCallback is used to get a callback when a cache entry is evicted
type UnLockCache ¶
type UnLockCache struct {
// contains filtered or unexported fields
}
UnLockCache implements a non-thread safe fixed size UnLockCache cache
func NewUnLockCache ¶
func NewUnLockCache(size int, onEvict EvictCallback) (*UnLockCache, error)
NewUnLockCache constructs an UnLockCache of the given size
func (*UnLockCache) Add ¶
func (c *UnLockCache) Add(key, value interface{}) (evicted bool)
Add adds a value to the cache. Returns true if an eviction occurred.
func (*UnLockCache) Contains ¶
func (c *UnLockCache) Contains(key interface{}) (ok bool)
Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.
func (*UnLockCache) Get ¶
func (c *UnLockCache) Get(key interface{}) (value interface{}, ok bool)
Get looks up a key's value from the cache.
func (*UnLockCache) GetOldest ¶
func (c *UnLockCache) GetOldest() (key interface{}, value interface{}, ok bool)
GetOldest returns the oldest entry
func (*UnLockCache) Keys ¶
func (c *UnLockCache) Keys() []interface{}
Keys returns a slice of the keys in the cache, from oldest to newest.
func (*UnLockCache) Len ¶
func (c *UnLockCache) Len() int
Len returns the number of items in the cache.
func (*UnLockCache) Peek ¶
func (c *UnLockCache) Peek(key interface{}) (value interface{}, ok bool)
Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
func (*UnLockCache) Purge ¶
func (c *UnLockCache) Purge()
Purge is used to completely clear the cache.
func (*UnLockCache) Remove ¶
func (c *UnLockCache) Remove(key interface{}) (present bool)
Remove removes the provided key from the cache, returning if the key was contained.
func (*UnLockCache) RemoveOldest ¶
func (c *UnLockCache) RemoveOldest() (key interface{}, value interface{}, ok bool)
RemoveOldest removes the oldest item from the cache.