Documentation ¶
Overview ¶
Package lru implement a thread safe lru cache inspired by https://github.com/golang/groupcache/tree/master/lru
Index ¶
- Constants
- type LRU
- func (l *LRU) Cap() int
- func (l *LRU) Contains(key interface{}) bool
- func (l *LRU) Get(key interface{}) (value interface{}, ok bool)
- func (l *LRU) GetOrSet(key, value interface{}) (newValue interface{}, isGet bool)
- func (l *LRU) Info() (hits int, misses int, maxSize int, currentSize int)
- func (l *LRU) Keys() []interface{}
- func (l *LRU) Len() int
- func (l *LRU) PopOldest() (key, value interface{})
- func (l *LRU) Purge()
- func (l *LRU) Remove(key interface{}) bool
- func (l *LRU) Set(key, value interface{}) (evicted bool)
Constants ¶
View Source
const (
// default LRU size
Default_LRU_Size = 1024
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
LRU implements a thread safe fixed size LRU cache
func (*LRU) GetOrSet ¶
return the value if the key exist, otherwise update the key by given value similar with redis SETNX
func (*LRU) Keys ¶
func (l *LRU) Keys() []interface{}
return all keys the LRU hold from oldest to newest
func (*LRU) PopOldest ¶
func (l *LRU) PopOldest() (key, value interface{})
Remove and return the oldest item from LRU
Click to show internal directories.
Click to hide internal directories.