add ForEachFunc

This commit is contained in:
Karl Seguin
2021-02-05 19:24:54 +08:00
parent 36ffada8b5
commit ae1872d700
7 changed files with 129 additions and 8 deletions

View File

@@ -76,6 +76,14 @@ func (c *Cache) DeleteFunc(matches func(key string, item *Item) bool) int {
return count
}
func (c *Cache) ForEachFunc(matches func(key string, item *Item) bool) {
for _, b := range c.buckets {
if !b.forEachFunc(matches) {
break
}
}
}
// 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
@@ -210,7 +218,7 @@ func (c *Cache) promote(item *Item) {
case c.promotables <- item:
default:
}
}
func (c *Cache) worker() {