Documentation ¶
Overview ¶
Package expirablelru implements a TTL expiring LRU cache based on the one at https://github.com/hashicorp/golang-lru/pull/68.
Only difference is the addition of the AddWithTTL method which allows users to set a TTL per-item.
Index ¶
- type Cache
- func (c *Cache) Add(key, value interface{}) (evicted bool)
- func (c *Cache) AddWithTTL(key, value interface{}, ttl time.Duration) (evicted bool)
- func (c *Cache) Close()
- func (c *Cache) Contains(key interface{}) (ok bool)
- func (c *Cache) DeleteExpired()
- func (c *Cache) Get(key interface{}) (interface{}, bool)
- func (c *Cache) GetOldest() (key, value interface{}, ok bool)
- func (c *Cache) Keys() []interface{}
- func (c *Cache) Len() int
- func (c *Cache) Peek(key interface{}) (interface{}, bool)
- func (c *Cache) Purge()
- func (c *Cache) Remove(key interface{}) bool
- func (c *Cache) RemoveOldest() (key, value interface{}, ok bool)
- func (c *Cache) Resize(size int) (evicted int)
- type EvictCallback
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
Cache implements a thread safe LRU with expirable entries.
func NewExpirableLRU ¶
func NewExpirableLRU(size int, onEvict EvictCallback, ttl, purgeEvery time.Duration) *Cache
NewExpirableLRU returns a new cache with expirable entries.
Size parameter set to 0 makes cache of unlimited size.
Providing 0 TTL turns expiring off.
Activates deleteExpired by purgeEvery duration. If MaxKeys and TTL are defined and PurgeEvery is zero, PurgeEvery will be set to 5 minutes.
func (*Cache) AddWithTTL ¶
AddWithTTL adds a key and a value with a TTL to the LRU interface
func (*Cache) Close ¶
func (c *Cache) Close()
Close cleans the cache and destroys running goroutines
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) DeleteExpired ¶
func (c *Cache) DeleteExpired()
DeleteExpired clears cache of expired items
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) 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