Documentation
¶
Overview ¶
Package cache provide LRU cache for memcached protocol. Note: Doc based on github.com/memcached/memcached/doc/new_lru.txt * There are HOT, WARM, and COLD LRU's. New items enter the HOT LRU. * LRU updates only happen as items reach the bottom of an LRU. If active in HOT, stay in HOT, if active in WARM, stay in WARM. If active in COLD, move to WARM. * HOT/WARM each capped at 32% of memory available for that slab class. COLD is uncapped (by default, as of this writing). * Items flow from HOT/WARM into COLD.
The primary goal is to better protect active items from "scanning". Items which are never hit again will flow from HOT, through COLD, and out the bottom. Items occasionally active (reaching COLD, but being hit before eviction), move to WARM. There they can stay relatively protected. A secondary goal is to improve latency. The LRU locks are no longer used on item reads, only during sets and deletes. TODO update doc after add LRU crawler.
Index ¶
- func IsCacheOverflow(err error) bool
- type Cache
- type Config
- type Deleter
- type Getter
- type Item
- type ItemMeta
- type ItemView
- type LRU
- func (c *LRU) Delete(key []byte) (deleted bool)
- func (c *LRU) Get(keys ...[]byte) (views []ItemView)
- func (c *LRU) NewDeleter(rawCommand []byte) Deleter
- func (c *LRU) NewGetter(rawCommand []byte) Getter
- func (c *LRU) NewSetter(rawCommand []byte) Setter
- func (c *LRU) Set(i Item)
- func (c *LRU) Touch(keys ...[]byte)
- type LockingLRU
- func (c *LockingLRU) Delete(key []byte) (deleted bool)
- func (c *LockingLRU) Get(keys ...[]byte) (views []ItemView)
- func (c *LockingLRU) Lock()
- func (c *LockingLRU) RLock()
- func (c *LockingLRU) RUnlock()
- func (c *LockingLRU) Set(i Item)
- func (c *LockingLRU) Snapshot() *Snapshot
- func (c *LockingLRU) Touch(keys ...[]byte)
- func (c *LockingLRU) Unlock()
- type RWCache
- type Setter
- type Snapshot
- type SnapshotReader
- type View
- type Viewable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsCacheOverflow ¶
Types ¶
type Cache ¶
type Cache interface { Set(i Item) Delete(key []byte) (deleted bool) // Get returns ItemReaders for keys that was found in cache. // views can be nil, if no key was found. Get(key ...[]byte) (views []ItemView) Touch(key ...[]byte) }
Handler implementation must not retain key slices.
type ItemView ¶
type ItemView struct { ItemMeta Reader *recycle.DataReader }
type LRU ¶
type LRU struct {
// contains filtered or unexported fields
}
LRU is Cache with auto locking on Cache operations.
func (*LRU) NewDeleter ¶
type LockingLRU ¶
type LockingLRU struct {
// contains filtered or unexported fields
}
LockingLRU is cache that requires explicit lock calls.
func NewLockingLRU ¶
func NewLockingLRU(l log.Logger, conf Config) *LockingLRU
func ReadLockingLRUSnapshot ¶
func ReadLockingLRUSnapshot(r SnapshotReader, p *recycle.Pool, l log.Logger, conf Config) (c *LockingLRU, err error)
func (*LockingLRU) Delete ¶
func (c *LockingLRU) Delete(key []byte) (deleted bool)
func (*LockingLRU) Get ¶
func (c *LockingLRU) Get(keys ...[]byte) (views []ItemView)
func (*LockingLRU) Lock ¶
func (c *LockingLRU) Lock()
func (*LockingLRU) RLock ¶
func (c *LockingLRU) RLock()
func (*LockingLRU) RUnlock ¶
func (c *LockingLRU) RUnlock()
func (*LockingLRU) Set ¶
func (c *LockingLRU) Set(i Item)
func (*LockingLRU) Snapshot ¶
func (c *LockingLRU) Snapshot() *Snapshot
func (*LockingLRU) Touch ¶
func (c *LockingLRU) Touch(keys ...[]byte)
func (*LockingLRU) Unlock ¶
func (c *LockingLRU) Unlock()
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot hold cache LRUs state for serialization. queueSnapshot is serialized as gob encoded snapshotInfo and sequence of queueSnapshots Note: until snapshot write it hold item data readers, what prevent data recycle. If snapshot will not be written, all data leak.
type SnapshotReader ¶
type SnapshotReader interface { io.Reader io.ByteReader }
type View ¶
type View interface { // NewSetter returns setter. // Provided rawCommand CAN be invalidated after call. // Implementations should copy it if needed. NewSetter(rawCommand []byte) Setter // NewGetter returns getter. // Provided rawCommand MUST NOT be invalidated Getter.Get call. NewGetter(rawCommand []byte) Getter // NewDeleter returns deleter. // Provided rawCommand MUST NOT be invalidated Deleter.Delete call. NewDeleter(rawCommand []byte) Deleter }
View interface that usually wraps Cache with additional logic per operation. Operation log, for example. Interfaces returned by View methods must be used only once.