ttlcache icon indicating copy to clipboard operation
ttlcache copied to clipboard

Add Range/ForEach method

Open swithek opened this issue 2 years ago • 2 comments

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.

swithek avatar Mar 29 '22 11:03 swithek

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).

swithek avatar Apr 01 '22 09:04 swithek

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.

swithek avatar Apr 01 '22 17:04 swithek