cache

package
v0.0.0-...-fbbe109 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2016 License: MIT Imports: 13 Imported by: 2

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCacheOverflow

func IsCacheOverflow(err error) bool

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 Config

type Config struct {
	Size int64
}

type Deleter

type Deleter interface {
	Delete(key []byte) (deleted bool)
}

type Getter

type Getter interface {
	Get(key ...[]byte) (views []ItemView)
}

type Item

type Item struct {
	ItemMeta
	Data *recycle.Data
}

func (Item) GoString

func (i Item) GoString() string

func (Item) NewView

func (i Item) NewView() ItemView

type ItemMeta

type ItemMeta struct {
	Key     string
	Flags   uint32
	Exptime int64
	Bytes   int
}

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 NewLRU

func NewLRU(l log.Logger, conf Config) *LRU

func (*LRU) Delete

func (c *LRU) Delete(key []byte) (deleted bool)

func (*LRU) Get

func (c *LRU) Get(keys ...[]byte) (views []ItemView)

func (*LRU) NewDeleter

func (c *LRU) NewDeleter(rawCommand []byte) Deleter

func (*LRU) NewGetter

func (c *LRU) NewGetter(rawCommand []byte) Getter

func (*LRU) NewSetter

func (c *LRU) NewSetter(rawCommand []byte) Setter

func (*LRU) Set

func (c *LRU) Set(i Item)

func (*LRU) Touch

func (c *LRU) Touch(keys ...[]byte)

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 RWCache

type RWCache interface {
	Cache
	sync.Locker
	RLock()
	RUnlock()
}

type Setter

type Setter interface {
	Set(i Item)
}

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.

func (*Snapshot) WriteTo

func (s *Snapshot) WriteTo(w io.Writer) (nn int64, err error)

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.

type Viewable

type Viewable interface {
	Cache
	View
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL