mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-07 06:03:09 -06:00
Namespace keys
This commit is contained in:
parent
2f3cd2828e
commit
da107c78da
|
|
@ -78,27 +78,30 @@ 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) {
|
||||||
|
strkey := fmt.Sprintf("%s_%v", c.Name, key)
|
||||||
if !c.Mutable {
|
if !c.Mutable {
|
||||||
if v, ok := c.cache.Get(key); ok && v != nil && !reflect.DeepEqual(v, value) {
|
if v, ok := c.cache.Get(strkey); 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))
|
panic(fmt.Sprintf("invalid use of immutable cache tries to change value of %v from %v to %v", strkey, v, value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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())
|
||||||
}
|
}
|
||||||
c.cache.SetWithTTL(key, value, cost, c.MaxAge)
|
c.cache.SetWithTTL(strkey, value, cost, c.MaxAge)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RistrettoCachePartition[K, V]) Unset(key K) {
|
func (c *RistrettoCachePartition[K, V]) Unset(key K) {
|
||||||
|
strkey := fmt.Sprintf("%s_%v", c.Name, key)
|
||||||
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", strkey))
|
||||||
}
|
}
|
||||||
c.cache.Del(key)
|
c.cache.Del(strkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RistrettoCachePartition[K, V]) Get(key K) (value V, ok bool) {
|
func (c *RistrettoCachePartition[K, V]) Get(key K) (value V, ok bool) {
|
||||||
v, ok := c.cache.Get(key)
|
strkey := fmt.Sprintf("%s_%v", c.Name, key)
|
||||||
|
v, ok := c.cache.Get(strkey)
|
||||||
if !ok || v == nil {
|
if !ok || v == nil {
|
||||||
var empty V
|
var empty V
|
||||||
return empty, false
|
return empty, false
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue