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
)
NoExpire Timers
Variables ¶
var (
ErrTableExists = errcode.New("table already exists")
)
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { // All returns a list of all tables at the node. All() []string // GetTableCache get TableCache GetTableCache(tab string) (TableCache, bool) // New Creates a new table. New(tab string, options ...OptionFunc) error // Insert the object or all of the objects in list. Insert(tab string, key, value interface{}) bool // InsertExpire inserts the object or all of the objects with expired time in list. InsertExpire(tab string, key, value interface{}, expire time.Duration) bool // Delete deletes the entire table Tab. Delete(tab string) bool // DeleteObject deletes all objects with key, Key from table Tab. DeleteObject(tab string, key interface{}) bool // DeleteObjects delete all objects in the table Tab. Remain table in cache. DeleteObjects(tab string) // Lookup Look up values with key, Key from table Tab. Lookup(tab string, key interface{}) ([]interface{}, bool) // LookupAll Look up all values in the Tab. LookupAll(tab string) (map[interface{}][]interface{}, bool) // Member Returns true if one or more elements in the table has key, otherwise false. Member(tab string, key interface{}) bool // Members Returns all keys in the table Tab. Members(tab string) ([]interface{}, bool) // SetExpire Set 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 { // Insert the object or all of the objects in list. Insert(key, values interface{}) bool // InsertExpire insert the object or all of the objects with expired time in list. InsertExpire(key, value interface{}, expire time.Duration) bool // DeleteObject Deletes all objects with key: Key. DeleteObject(key interface{}) bool // DeleteObjects Delete all objects in the table Tab. Remain table in cache. DeleteObjects() // Member Returns true if one or more elements in the table has key: Key, otherwise false. Member(key interface{}) bool // Members Returns all keys in the table Tab. Members() ([]interface{}, bool) // Lookup Look up values with key: Key. Lookup(key interface{}) ([]interface{}, bool) // LookupAll Look up all values in the Tab. LookupAll() (map[interface{}][]interface{}, bool) // SetExpire 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 ( // ValueModeUnique only one value ValueModeUnique ValueMode = iota // ValueModeBag The table is a bag table, which can have many objects // but only one instance of each object, per key. ValueModeBag // ValueModeDuplicateBag The table is a duplicate_bag table, which can have many objects, // including multiple copies of the same object, per key. ValueModeDuplicateBag )
ValueMode