From 80d38305e5f6af955ef73afc2e288f31818a5b8b Mon Sep 17 00:00:00 2001 From: Daker Fernandes Pinheiro Date: Tue, 29 Nov 2016 17:48:59 -0300 Subject: [PATCH] Add Clear methods to lru cache --- lru/lru.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 @@ func (c *Cache) Len() int { } 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 +}