commit | 6159c0a623a530b7a9937cfec865f7376844357e | [log] [tgz] |
---|---|---|
author | Brad Fitzpatrick <brad@danga.com> | Wed Jan 04 12:20:46 2017 -0800 |
committer | GitHub <noreply@github.com> | Wed Jan 04 12:20:46 2017 -0800 |
tree | 83ae7644b1b7e0b2640ef0068518d2004d85d8d1 | |
parent | d092608c065831f1984ac9d332ca5b2c95a11f57 [diff] | |
parent | 80d38305e5f6af955ef73afc2e288f31818a5b8b [diff] |
Merge pull request #76 from dakerfp/patch-1 Add Clear methods to lru cache
diff --git a/lru/lru.go b/lru/lru.go index cdfe299..532cc45 100644 --- a/lru/lru.go +++ b/lru/lru.go
@@ -119,3 +119,15 @@ } return c.ll.Len() } + +// Clear purges all stored items from the cache. +func (c *Cache) Clear() { + if c.OnEvicted != nil { + for _, e := range c.cache { + kv := e.Value.(*entry) + c.OnEvicted(kv.key, kv.value) + } + } + c.ll = nil + c.cache = nil +}