mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-08 14:43:09 -06:00
Clean up a bit
This commit is contained in:
parent
ad40b054bc
commit
03cd7f041b
|
|
@ -1,19 +1,9 @@
|
||||||
package caching
|
package caching
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
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 {
|
type LazyLoadCache interface {
|
||||||
StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string)
|
StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string)
|
||||||
IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool)
|
IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool)
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,6 @@ import (
|
||||||
"github.com/matrix-org/dendrite/roomserver/types"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
RoomServerRoomIDsCacheName = "roomserver_room_ids"
|
|
||||||
RoomServerRoomIDsCacheMaxEntries = 1024
|
|
||||||
RoomServerRoomIDsCacheMutable = false
|
|
||||||
RoomServerRoomIDsCacheMaxAge = CacheNoMaxAge
|
|
||||||
)
|
|
||||||
|
|
||||||
type RoomServerCaches interface {
|
type RoomServerCaches interface {
|
||||||
RoomServerNIDsCache
|
RoomServerNIDsCache
|
||||||
RoomVersionCache
|
RoomVersionCache
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,15 @@ func NewRistrettoCache(maxCost CacheSize, enablePrometheus bool) (*Caches, error
|
||||||
}, nil
|
}, 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 {
|
type RistrettoCachePartition[K keyable, V any] struct {
|
||||||
cache *ristretto.Cache
|
cache *ristretto.Cache
|
||||||
Prefix byte
|
Prefix byte
|
||||||
|
|
@ -164,12 +173,3 @@ func (c *RistrettoCachePartition[K, V]) Get(key K) (value V, ok bool) {
|
||||||
value, ok = v.(V)
|
value, ok = v.(V)
|
||||||
return
|
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))
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
if err != nil {
|
||||||
logrus.WithError(err).Warnf("Failed to create cache")
|
logrus.WithError(err).Warnf("Failed to create cache")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue