Store caches key and value in the cache.
(key, value interface{})
| 20 | |
| 21 | // Store caches key and value in the cache. |
| 22 | func (c *Cache) Store(key, value interface{}) { |
| 23 | c.mx.Lock() |
| 24 | |
| 25 | if c.nentries == maxCacheEntries { |
| 26 | c.nentries -= c.clear() |
| 27 | } |
| 28 | |
| 29 | if _, loaded := c.cache.LoadOrStore(key, value); !loaded { |
| 30 | c.nentries++ |
| 31 | } |
| 32 | |
| 33 | c.mx.Unlock() |
| 34 | } |
| 35 | |
| 36 | // Load loads from the cache the value that is mapped to key, or bool if |
| 37 | // the cache doesn't contain key. |