Skip to content

Commit

Permalink
Merge pull request #76 from dakerfp/patch-1
Browse files Browse the repository at this point in the history
Add Clear methods to lru cache
  • Loading branch information
bradfitz committed Jan 4, 2017
2 parents d092608 + 80d3830 commit 6159c0a
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 6159c0a

Please sign in to comment.