jellydator / ttlcache

An in-memory cache with item expiration and generics
MIT License
930 stars 116 forks source link

Protect Range from empty cache #119

Closed rolsim closed 9 months ago

rolsim commented 9 months ago
func (c *Cache[K, V]) Range(fn func(item *Item[K, V]) bool) {
    c.items.mu.RLock()

>   if len(c.items.values) == 0 {
>       c.items.mu.RUnlock()
>       return
>   }

    for item := c.items.lru.Front(); item != c.items.lru.Back().Next(); item = item.Next() {
    ...
swithek commented 9 months ago

This bug has been fixed here: #118

I've just made a new release that includes this fix: https://github.com/jellydator/ttlcache/releases/tag/v3.1.1