# README
cache
light cache in go
Introduction
Installation
go get "github.com/iTrellis/cache"
Features
- Simple lru
- It can set Unique | Bag | DuplicateBag values per key
TODO
- main node: to manage cache
- consistent hash to several nodes to install keys
Cache
cache is manager for k-vs tables base on TableCache
// Cache Manager functions for executing k-v tables base on TableCache
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
}
TableCache
table cache is manager for k-vs
// 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
}
Sample: NewTableCache with options
# Packages
No description provided by the author
# Functions
New return cache manager.
NewLRU constructs an LRU of the given options.
NewTableCache constructs a fixed size cache.
OptionEvict set the evict ballback.
OptionKeySize set the size of keys.
OptionValueMode set the values' model.
# Constants
Timers.
The table is a bag table, which can have many objects but only one instance of each object, per key.
The table is a duplicate_bag table, which can have many objects, including multiple copies of the same object, per key.
only one value.
# Variables
errors.
errors.
errors.
errors.
errors.
# Structs
DataValues define k-vs struct.
LRU implements a non-thread safe fixed size LRU cache.
Options configure.
# Interfaces
Cache Manager functions for executing k-v tables base on TableCache.
TableCache table manager for k-vs functions.
# Type aliases
EvictCallback is used to get a callback when a cache entry is evicted.
OptionFunc 参数处理函数.
ValueMode define value mode.