mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-07 06:03:09 -06:00
Try this
This commit is contained in:
parent
9a3f483e9c
commit
b7a908305e
|
|
@ -15,7 +15,7 @@ import (
|
||||||
|
|
||||||
func NewRistrettoCache(maxCost CacheSize, enablePrometheus bool) (*Caches, error) {
|
func NewRistrettoCache(maxCost CacheSize, enablePrometheus bool) (*Caches, error) {
|
||||||
cache, err := ristretto.NewCache(&ristretto.Config{
|
cache, err := ristretto.NewCache(&ristretto.Config{
|
||||||
NumCounters: 1e6,
|
NumCounters: 1e7,
|
||||||
MaxCost: int64(maxCost),
|
MaxCost: int64(maxCost),
|
||||||
BufferItems: 64,
|
BufferItems: 64,
|
||||||
Metrics: true,
|
Metrics: true,
|
||||||
|
|
@ -52,9 +52,8 @@ func NewRistrettoCache(maxCost CacheSize, enablePrometheus bool) (*Caches, error
|
||||||
Name: "room_ids",
|
Name: "room_ids",
|
||||||
},
|
},
|
||||||
RoomServerEvents: &RistrettoCachePartition[int64, *gomatrixserverlib.Event]{
|
RoomServerEvents: &RistrettoCachePartition[int64, *gomatrixserverlib.Event]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Name: "room_events",
|
Name: "room_events",
|
||||||
Mutable: true,
|
|
||||||
},
|
},
|
||||||
RoomInfos: &RistrettoCachePartition[string, types.RoomInfo]{
|
RoomInfos: &RistrettoCachePartition[string, types.RoomInfo]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
|
|
@ -93,7 +92,7 @@ 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)
|
strkey := fmt.Sprintf("%v\000%s", key, c.Name)
|
||||||
if !c.Mutable {
|
if !c.Mutable {
|
||||||
if v, ok := c.cache.Get(strkey); 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", strkey, v, value))
|
panic(fmt.Sprintf("invalid use of immutable cache tries to change value of %v from %v to %v", strkey, v, value))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue