Skip to content

Commit

Permalink
Add Clear methods to lru cache
Browse files Browse the repository at this point in the history
  • Loading branch information
dakerfp committed Dec 23, 2016
1 parent d092608 commit 80d3830
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lru/lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 80d3830

Please sign in to comment.