Make less panicky

This commit is contained in:
Neil Alexander 2022-06-14 14:16:59 +01:00
parent 800dbbf9e4
commit 2488058e62
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -78,10 +78,12 @@ type RistrettoCachePartition[K keyable, V any] struct {
func (c *RistrettoCachePartition[K, V]) Set(key K, value V) {
if !c.Mutable {
if _, ok := c.cache.Get(key); ok {
if v, ok := c.cache.Get(key); ok {
if fmt.Sprintf("%v", v) != fmt.Sprintf("%v", value) { // TODO: this is yucky
panic(fmt.Sprintf("invalid use of immutable cache tries to replace value of %v", key))
}
}
}
cost := int64(1)
if cv, ok := any(value).(costable); ok {
cost = int64(cv.CacheCost())