Merge pull request #76 from dakerfp/patch-1

Add Clear methods to lru cache
This commit is contained in:
Brad Fitzpatrick 2017-01-04 12:20:46 -08:00 committed by GitHub
commit 6159c0a623

View File

@ -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
}