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

@@ -154,6 +154,11 @@ func (c *LayeredCache) DeletePrefix(primary, prefix string) int {
return c.bucket(primary).deletePrefix(primary, prefix, c.deletables)
}
// Deletes all items that share the same primary key and where the matches func evaluates to true.
func (c *LayeredCache) DeleteFunc(primary string, matches func(key string, item interface{}) bool) int {
return c.bucket(primary).deleteFunc(primary, matches, c.deletables)
}
//this isn't thread safe. It's meant to be called from non-concurrent tests
func (c *LayeredCache) Clear() {
for _, bucket := range c.buckets {