Documentation
¶
Overview ¶
Package cache provides interface and implementation of a cache algorithms.
Index ¶
- type Cache
- func (r *Cache) Add(key, value interface{}, blockNum uint64) bool
- func (r *Cache) Close() error
- func (r *Cache) Delete(key interface{}) bool
- func (r *Cache) EvictWithStrategy(strategy func(blockNum uint64) bool) int
- func (r *Cache) Get(key interface{}) (val interface{}, blockNum uint64)
- func (r *Cache) Nodes() int
- func (r *Cache) Purge()
- func (r *Cache) Size() int
- type Cacher
- type Handle
- type Node
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a 'cache map'.
func (*Cache) Add ¶
Add sets k,v data and the blockNum when inserting into cache. It returns true if the data pair is inserted into the cache successfully.
func (*Cache) Delete ¶
Delete removes and ban 'cache node' with the given namespace and key. A banned 'cache node' will never inserted into the 'cache tree'. Ban only attributed to the particular 'cache node', so when a 'cache node' is recreated it will not be banned.
Delete return true is such 'cache node' exist.
func (*Cache) EvictWithStrategy ¶
type Cacher ¶
type Cacher interface {
// Promote promotes the 'cache node'.
Promote(n *Node)
// Ban evicts the 'cache node' and prevent subsequent 'promote'.
Ban(n *Node)
// Evict evicts the 'cache node'.
Evict(n *Node)
// EvictWithStrategy evicts 'cache node' with a given strategy.
//
// It returns the number of the evicted `cache node`
EvictWithStrategy(st func(blockNum uint64) bool) int
// EvictAll evicts all 'cache node'.
EvictAll()
// Close closes the 'cache tree'
Close() error
}
Cacher provides interface to implements a caching functionality. An implementation must be safe for concurrent use.
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle is a 'cache handle' of a 'cache node'.