ttlcache
ttlcache copied to clipboard
Add Range/ForEach method
It should iterate over all cache items and pass each of them into a func that is provided as a parameter:
func (c *Cache[K, V]) Range(fn func(*Item[K, V]) bool) {
// ...
}
The bool return value should indicate whether the iteration should continue or be stopped.
And I think it shouldn't extend the expiration time of the active loop item when it's being loaded and passed into the func (i.e., it should work like the Items()
method).
It should work like sync.Map's Range and it should be possible to call Set()
, etc. methods from within the provided func without any deadlocks.