Documentation
¶
Overview ¶
Package cache implement a memory-based LRU local cache
Index ¶
- type ConcurrencyLRUCache
- func (cl *ConcurrencyLRUCache) DECR(key string, expireTime time.Duration) (int64, error)
- func (cl *ConcurrencyLRUCache) Delete(key string)
- func (cl *ConcurrencyLRUCache) Get(key string) (interface{}, error)
- func (cl *ConcurrencyLRUCache) INCR(key string, expireTime time.Duration) (int64, error)
- func (cl *ConcurrencyLRUCache) Set(key string, value interface{}, expireTime time.Duration) error
- func (cl *ConcurrencyLRUCache) SetIfNX(key string, value interface{}, expireTime time.Duration) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrencyLRUCache ¶
type ConcurrencyLRUCache struct {
// contains filtered or unexported fields
}
ConcurrencyLRUCache is a memory-based LRU local cache, default total 16 segment to improve concurrent performance LRU is not real least recently used for the total cache,but just for each buket we just need a proper method to clear cache
func New ¶
func New(maxEntries int) *ConcurrencyLRUCache
New create an instance of ConcurrencyLRUCache maxEntries the cache size, will to convert to (n/16+n%16>0?1:0)*16
func (*ConcurrencyLRUCache) DECR ¶
DECR minus one to the value(must int64) of the key,if the key not exist, initialize with 0 and then minus one
func (*ConcurrencyLRUCache) Delete ¶
func (cl *ConcurrencyLRUCache) Delete(key string)
Delete delete the value by key, no error returned
func (*ConcurrencyLRUCache) Get ¶
func (cl *ConcurrencyLRUCache) Get(key string) (interface{}, error)
Get get the value of a cached element by key. If key do not exist, this function will return nil and an error msg
key: The identity of an element return: value: the cached value, nil if key do not exist err: error info, nil if value is not nil
func (*ConcurrencyLRUCache) INCR ¶
INCR add one to the value(must int64) of the key , if the key not exist, initialize with 0 and then add one
func (*ConcurrencyLRUCache) Set ¶
func (cl *ConcurrencyLRUCache) Set(key string, value interface{}, expireTime time.Duration) error
Set create or update an element using key
key: The identity of an element value: new value of the element expireTime: expire time, positive int64 or -1 which means never overdue