mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-07 06:03:09 -06:00
Determine mutability using deep equality
This commit is contained in:
parent
e1f4a485f5
commit
8147d8367d
|
|
@ -38,6 +38,10 @@ type costable interface {
|
||||||
CacheCost() int64
|
CacheCost() int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type equatable interface {
|
||||||
|
comparable
|
||||||
|
}
|
||||||
|
|
||||||
type CacheSize int64
|
type CacheSize int64
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package caching
|
package caching
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dgraph-io/ristretto"
|
"github.com/dgraph-io/ristretto"
|
||||||
|
|
@ -76,15 +78,11 @@ 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 !c.Mutable {
|
if v, ok := c.cache.Get(key); ok && !reflect.DeepEqual(v, value) {
|
||||||
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())
|
||||||
|
|
@ -96,11 +94,9 @@ func (c *RistrettoCachePartition[K, V]) Unset(key K) {
|
||||||
if c.cache == nil {
|
if c.cache == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
/*
|
if !c.Mutable {
|
||||||
if !c.Mutable {
|
panic(fmt.Sprintf("invalid use of immutable cache tries to unset value of %v", key))
|
||||||
panic(fmt.Sprintf("invalid use of immutable cache tries to unset value of %v", key))
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
c.cache.Del(key)
|
c.cache.Del(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue