Documentation ¶
Index ¶
- Constants
- Variables
- type Cache
- type DataValues
- type EvictCallback
- type LRU
- func (p *LRU) DeleteObject(key interface{}) (present bool)
- func (p *LRU) DeleteObjects()
- func (p *LRU) Insert(key, value interface{}) (evicted bool)
- func (p *LRU) InsertExpire(key, value interface{}, expire time.Duration) bool
- func (p *LRU) Lookup(key interface{}) ([]interface{}, bool)
- func (p *LRU) LookupAll() (items map[interface{}][]interface{}, ok bool)
- func (p *LRU) Member(key interface{}) bool
- func (p *LRU) Members() (keys []interface{}, ok bool)
- func (p *LRU) RemoveOldest() (key, value interface{}, ok bool)
- func (p *LRU) SetExpire(key interface{}, expire time.Duration) bool
- type OptionFunc
- type Options
- type TableCache
- type ValueMode
Constants ¶
const (
NoExpire time.Duration = 0
)
Timers
Variables ¶
var ( ErrTableExists = errors.New("table already exists") ErrNewTableCache = errors.New("failed new table") ErrOrderSetMustBeBool = errors.New("order set must be bool") ErrUnknownTableOption = errors.New("unknown table option") ErrUnknownTableValueMode = errors.New("unknown table value mode") )
errors
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { // Returns a list of all tables at the node. All() []string // Get TableCache GetTableCache(tab string) (TableCache, bool) // Creates a new table. New(tab string, options ...OptionFunc) error // Inserts the object or all of the objects in list. Insert(tab string, key, value interface{}) bool // Inserts the object or all of the objects with expired time in list. InsertExpire(tab string, key, value interface{}, expire time.Duration) bool // Deletes the entire table Tab. Delete(tab string) bool // Deletes all objects with key, Key from table Tab. DeleteObject(tab string, key interface{}) bool // Delete all objects in the table Tab. Remain table in cache. DeleteObjects(tab string) // Look up values with key, Key from table Tab. Lookup(tab string, key interface{}) ([]interface{}, bool) // Look up all values in the Tab. LookupAll(tab string) (map[interface{}][]interface{}, bool) // Returns true if one or more elements in the table has key Key, otherwise false. Member(tab string, key interface{}) bool // Retruns all keys in the table Tab. Members(tab string) ([]interface{}, bool) // Set key Key expire time in the table Tab. SetExpire(tab string, key interface{}, expire time.Duration) bool }
Cache Manager functions for executing k-v tables base on TableCache
type DataValues ¶
type DataValues struct { Key interface{} Values []interface{} Exists map[interface{}]bool Expire *time.Time }
DataValues define k-vs struct
type EvictCallback ¶
type EvictCallback func(key interface{}, value interface{})
EvictCallback 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) DeleteObject ¶
DeleteObject deletes the provided key from the cache, returning if the key was contained.
func (*LRU) DeleteObjects ¶
func (p *LRU) DeleteObjects()
DeleteObjects is used to completely clear the cache.
func (*LRU) InsertExpire ¶
InsertExpire insert a value to the cache. Returns true if insert kv successful.
func (*LRU) Member ¶
Member Returns true if one or more elements in the table has key: Key, otherwise false.
func (*LRU) RemoveOldest ¶
RemoveOldest removes the oldest item from the cache.
type OptionFunc ¶
type OptionFunc func(*Options)
OptionFunc 参数处理函数
func OptionEvict ¶
func OptionEvict(evict EvictCallback) OptionFunc
OptionEvict set the evict ballback
func OptionValueMode ¶
func OptionValueMode(mode ValueMode) OptionFunc
OptionValueMode set the values' model
type Options ¶
type Options struct { ValueMode ValueMode Size int Evict EvictCallback }
Options configure
type TableCache ¶
type TableCache interface { // Inserts the object or all of the objects in list. Insert(key, values interface{}) bool // Inserts the object or all of the objects with expired time in list. InsertExpire(key, value interface{}, expire time.Duration) bool // Deletes all objects with key: Key. DeleteObject(key interface{}) bool // Delete all objects in the table Tab. Remain table in cache. DeleteObjects() // Returns true if one or more elements in the table has key: Key, otherwise false. Member(key interface{}) bool // Retruns all keys in the table Tab. Members() ([]interface{}, bool) // Look up values with key: Key. Lookup(key interface{}) ([]interface{}, bool) // Look up all values in the Tab. LookupAll() (map[interface{}][]interface{}, bool) // Set Key Expire time SetExpire(key interface{}, expire time.Duration) bool }
TableCache table manager for k-vs functions
func NewTableCache ¶
func NewTableCache(name string, opts ...OptionFunc) (TableCache, error)
NewTableCache constructs a fixed size cache.
type ValueMode ¶
type ValueMode int
ValueMode define value mode
const ( // only one value ValueModeUnique ValueMode = iota // The table is a bag table, which can have many objects // but only one instance of each object, per key. ValueModeBag // The table is a duplicate_bag table, which can have many objects, // including multiple copies of the same object, per key. ValueModeDuplicateBag )
ValueMode