MCPcopy Create free account
hub / github.com/CPChain/chain / Get

Method Get

commons/cache/lru_expire_cache.go:32–44  ·  view source on GitHub ↗

get unexpired element from lru cache

(key interface{})

Source from the content-addressed store, hash-verified

30
31// get unexpired element from lru cache
32func (c *LRUExpireCache) Get(key interface{}) (interface{}, bool) {
33 c.lock.Lock()
34 defer c.lock.Unlock()
35 e, ok := c.cache.Get(key)
36 if !ok {
37 return nil, false
38 }
39 if c.clock.Now().After(e.(*cacheEntry).expireTime) {
40 c.cache.Remove(key)
41 return nil, false
42 }
43 return e.(*cacheEntry).value, true
44}
45
46// remove element
47func (c *LRUExpireCache) Remove(key interface{}) {

Callers 2

TestNewLRUExpireCache1Function · 0.95
TestNewLRUExpireCache2Function · 0.95

Calls 5

LockMethod · 0.80
UnlockMethod · 0.80
GetMethod · 0.65
NowMethod · 0.65
RemoveMethod · 0.45

Tested by 2

TestNewLRUExpireCache1Function · 0.76
TestNewLRUExpireCache2Function · 0.76