Documentation ¶
Index ¶
- Constants
- type BufferStat
- type Chunk
- type EvictCallback
- type FuncLruDel
- type KVBuffer
- type LRU
- func (c *LRU) Add(key, value interface{}) (evicted bool)
- func (c *LRU) Contains(key interface{}) (ok bool)
- func (c *LRU) Get(key interface{}) (value interface{}, ok bool)
- func (c *LRU) GetOldest() (key, value interface{}, ok bool)
- func (c *LRU) Keys() []interface{}
- func (c *LRU) Len() int
- func (c *LRU) Peek(key interface{}) (value interface{}, ok bool)
- func (c *LRU) Purge()
- func (c *LRU) Remove(key interface{}) (present bool)
- func (c *LRU) RemoveOldest() (key, value interface{}, ok bool)
- func (c *LRU) Resize(size int) (evicted int)
- type Node
Constants ¶
const (
HeaderSize int = 16 // 0xFEDCBA98 chunkSize4 dataSize8
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferStat ¶
type EvictCallback ¶
type EvictCallback func(key interface{}, value interface{})
EvictCallback is used to get a callback when a cache entry is evicted
type FuncLruDel ¶
type KVBuffer ¶
type KVBuffer struct {
// contains filtered or unexported fields
}
Buffer implements a kv buffer.
func NewLRUKVBuffer ¶
func NewLRUKVBuffer(data []byte, chunkSize int, onLruDel FuncLruDel) (*KVBuffer, error)
NewBuffer constructs a Buffer.
func (*KVBuffer) Stat ¶
func (b *KVBuffer) Stat() BufferStat
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
LRU implements a non-thread safe fixed size LRU cache
func NewLRU ¶
func NewLRU(size int, onEvict EvictCallback) (*LRU, error)
NewLRU constructs an LRU of the given size
func (*LRU) Contains ¶
Contains checks if a key is in the cache, without updating the recent-ness or deleting it for being stale.
func (*LRU) Keys ¶
func (c *LRU) Keys() []interface{}
Keys returns a slice of the keys in the cache, from oldest to newest.
func (*LRU) Peek ¶
Peek returns the key value (or undefined if not found) without updating the "recently used"-ness of the key.
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.