Documentation ¶
Index ¶
- func NewLRU(config *Config) (interfaces.LRU, error)
- type Config
- type Entry
- type EvictedCallback
- type LRU
- func (c *LRU) Add(key, value interface{}) bool
- func (c *LRU) Contains(key interface{}) bool
- func (c *LRU) Get(key interface{}) (interface{}, bool)
- func (c *LRU) Len() int
- func (c *LRU) MaxSize() int64
- func (c *LRU) Metrics() string
- func (c *LRU) Peek(key interface{}) (interface{}, bool)
- func (c *LRU) Purge()
- func (c *LRU) PushBack(key, value interface{}) bool
- func (c *LRU) Remove(key interface{}) (present bool)
- func (c *LRU) RemoveOldest() (interface{}, bool)
- func (c *LRU) Size() int64
- type SizeFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { // Function to calculate size of cache entries. SizeFn SizeFn // Optional callback for cache eviction events. OnEvict EvictedCallback // Maximum amount of data to store in the cache. // The size of each entry is determined by SizeFn. MaxSize int64 }
Config specifies how the LRU cache is to be constructed. MaxSize & SizeFn are required.
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry is used to hold a value in the evictList
type EvictedCallback ¶
type EvictedCallback func(value interface{})
EvictedCallback is used to get a callback when a cache Entry is evicted
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
LRU implements a non-thread safe fixed size LRU cache
func (*LRU) Peek ¶
Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
func (*LRU) PushBack ¶
PushBack adds a value to the back of the cache. Returns true if the key was added.
func (*LRU) Remove ¶
Remove removes the provided key from the cache, returning if the key was contained.
func (*LRU) RemoveOldest ¶
RemoveOldest removes the oldest item from the cache.
Click to show internal directories.
Click to hide internal directories.