Clean up a bit

This commit is contained in:
Neil Alexander 2022-06-16 09:50:40 +01:00
parent ad40b054bc
commit 03cd7f041b
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 10 additions and 27 deletions

View file

@ -1,19 +1,9 @@
package caching
import (
"time"
userapi "github.com/matrix-org/dendrite/userapi/api"
)
const (
LazyLoadCacheName = "lazy_load_members"
LazyLoadCacheMaxEntries = 128
LazyLoadCacheMaxUserEntries = 128
LazyLoadCacheMutable = true
LazyLoadCacheMaxAge = time.Minute * 30
)
type LazyLoadCache interface {
StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string)
IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool)

View file

@ -4,13 +4,6 @@ import (
"github.com/matrix-org/dendrite/roomserver/types"
)
const (
RoomServerRoomIDsCacheName = "roomserver_room_ids"
RoomServerRoomIDsCacheMaxEntries = 1024
RoomServerRoomIDsCacheMutable = false
RoomServerRoomIDsCacheMaxAge = CacheNoMaxAge
)
type RoomServerCaches interface {
RoomServerNIDsCache
RoomVersionCache

View file

@ -119,6 +119,15 @@ func NewRistrettoCache(maxCost CacheSize, enablePrometheus bool) (*Caches, error
}, nil
}
type RistrettoCostedCachePartition[k keyable, v costable] struct {
*RistrettoCachePartition[k, v]
}
func (c *RistrettoCostedCachePartition[K, V]) Set(key K, value V) {
cost := value.CacheCost()
c.setWithCost(key, value, int64(cost))
}
type RistrettoCachePartition[K keyable, V any] struct {
cache *ristretto.Cache
Prefix byte
@ -164,12 +173,3 @@ func (c *RistrettoCachePartition[K, V]) Get(key K) (value V, ok bool) {
value, ok = v.(V)
return
}
type RistrettoCostedCachePartition[k keyable, v costable] struct {
*RistrettoCachePartition[k, v]
}
func (c *RistrettoCostedCachePartition[K, V]) Set(key K, value V) {
cost := value.CacheCost()
c.setWithCost(key, value, int64(cost))
}

View file

@ -161,7 +161,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base
}
}
cache, err := caching.NewRistrettoCache(1*caching.GB, enableMetrics)
cache, err := caching.NewRistrettoCache(caching.MB*64, enableMetrics)
if err != nil {
logrus.WithError(err).Warnf("Failed to create cache")
}