Add DeleteFunc

This shares DeletePrefixs's implementation.
This commit is contained in:
Bjørn Erik Pedersen
2020-08-12 17:30:28 +02:00
parent 223703f7f0
commit d56665a86e
6 changed files with 90 additions and 2 deletions

View File

@@ -63,6 +63,15 @@ func (c *Cache) DeletePrefix(prefix string) int {
return count
}
// Deletes all items that the matches func evaluates to true.
func (c *Cache) DeleteFunc(matches func(key string, item interface{}) bool) int {
count := 0
for _, b := range c.buckets {
count += b.deleteFunc(matches, c.deletables)
}
return count
}
// Get an item from the cache. Returns nil if the item wasn't found.
// This can return an expired item. Use item.Expired() to see if the item
// is expired and item.TTL() to see how long until the item expires (which