Don't enforce mutability checks for now

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

View file

@ -1,7 +1,6 @@
package caching package caching
import ( import (
"fmt"
"time" "time"
"github.com/dgraph-io/ristretto" "github.com/dgraph-io/ristretto"
@ -77,13 +76,15 @@ type RistrettoCachePartition[K keyable, V any] struct {
} }
func (c *RistrettoCachePartition[K, V]) Set(key K, value V) { func (c *RistrettoCachePartition[K, V]) Set(key K, value V) {
if !c.Mutable { /*
if v, ok := c.cache.Get(key); ok { if !c.Mutable {
if fmt.Sprintf("%v", v) != fmt.Sprintf("%v", value) { // TODO: this is yucky if v, ok := c.cache.Get(key); ok {
panic(fmt.Sprintf("invalid use of immutable cache tries to replace value of %v", key)) 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) cost := int64(1)
if cv, ok := any(value).(costable); ok { if cv, ok := any(value).(costable); ok {
cost = int64(cv.CacheCost()) cost = int64(cv.CacheCost())
@ -95,9 +96,11 @@ func (c *RistrettoCachePartition[K, V]) Unset(key K) {
if c.cache == nil { if c.cache == nil {
return return
} }
if !c.Mutable { /*
panic(fmt.Sprintf("invalid use of immutable cache tries to unset value of %v", key)) if !c.Mutable {
} panic(fmt.Sprintf("invalid use of immutable cache tries to unset value of %v", key))
}
*/
c.cache.Del(key) c.cache.Del(key)
} }