Skip to content

Commit 6159c0a

Browse files
authored
Merge pull request #76 from dakerfp/patch-1
Add Clear methods to lru cache
2 parents d092608 + 80d3830 commit 6159c0a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lru/lru.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,15 @@ func (c *Cache) Len() int {
119119
}
120120
return c.ll.Len()
121121
}
122+
123+
// Clear purges all stored items from the cache.
124+
func (c *Cache) Clear() {
125+
if c.OnEvicted != nil {
126+
for _, e := range c.cache {
127+
kv := e.Value.(*entry)
128+
c.OnEvicted(kv.key, kv.value)
129+
}
130+
}
131+
c.ll = nil
132+
c.cache = nil
133+
}

0 commit comments

Comments
 (0)