Add Clear methods to lru cache

This commit is contained in:
Daker Fernandes Pinheiro 2016-11-29 17:48:59 -03:00 committed by Daker Pinheiro
parent d092608c06
commit 80d38305e5

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
}