diff --git a/internal/caching/caches.go b/internal/caching/caches.go index f04fb175f..1b456717c 100644 --- a/internal/caching/caches.go +++ b/internal/caching/caches.go @@ -38,10 +38,6 @@ type costable interface { CacheCost() int64 } -type equatable interface { - comparable -} - type CacheSize int64 const ( diff --git a/internal/caching/impl_ristretto.go b/internal/caching/impl_ristretto.go index c74387502..312aef83a 100644 --- a/internal/caching/impl_ristretto.go +++ b/internal/caching/impl_ristretto.go @@ -79,8 +79,8 @@ type RistrettoCachePartition[K keyable, V any] struct { func (c *RistrettoCachePartition[K, V]) Set(key K, value V) { if !c.Mutable { - if v, ok := c.cache.Get(key); ok && !reflect.DeepEqual(v, value) { - panic(fmt.Sprintf("invalid use of immutable cache tries to replace value of %v", key)) + if v, ok := c.cache.Get(key); ok && v != nil && !reflect.DeepEqual(v, value) { + panic(fmt.Sprintf("invalid use of immutable cache tries to change value of %v from %v to %v", key, v, value)) } } cost := int64(1) @@ -91,9 +91,6 @@ func (c *RistrettoCachePartition[K, V]) Set(key K, value V) { } func (c *RistrettoCachePartition[K, V]) Unset(key K) { - if c.cache == nil { - return - } if !c.Mutable { panic(fmt.Sprintf("invalid use of immutable cache tries to unset value of %v", key)) } @@ -101,11 +98,11 @@ func (c *RistrettoCachePartition[K, V]) Unset(key K) { } func (c *RistrettoCachePartition[K, V]) Get(key K) (value V, ok bool) { - if c.cache == nil { + v, ok := c.cache.Get(key) + if !ok || v == nil { var empty V return empty, false } - v, ok := c.cache.Get(key) value, ok = v.(V) return }