mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-07 06:03:09 -06:00
Add back some lazy loading caching
This commit is contained in:
parent
0647844636
commit
858cc61f92
|
|
@ -4,61 +4,32 @@ import (
|
|||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
||||
type lazyLoadingCacheKey struct {
|
||||
UserID string // the user we're querying on behalf of
|
||||
DeviceID string // the user we're querying on behalf of
|
||||
RoomID string // the room in question
|
||||
TargetUserID string // the user whose membership we're asking about
|
||||
}
|
||||
|
||||
type LazyLoadCache interface {
|
||||
StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string)
|
||||
IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool)
|
||||
}
|
||||
|
||||
func (c Caches) lazyLoadCacheForUser(device *userapi.Device) (*RistrettoCachePartition[string, any], error) {
|
||||
return nil, nil
|
||||
/*
|
||||
cacheName := fmt.Sprintf("%s/%s", device.UserID, device.ID)
|
||||
userCache, ok := c.LazyLoading.Get(cacheName)
|
||||
if ok && userCache != nil {
|
||||
if cache, ok := userCache.(*InMemoryLRUCachePartition); ok {
|
||||
return cache, nil
|
||||
}
|
||||
}
|
||||
cache, err := NewInMemoryLRUCachePartition(
|
||||
LazyLoadCacheName,
|
||||
LazyLoadCacheMutable,
|
||||
LazyLoadCacheMaxUserEntries,
|
||||
LazyLoadCacheMaxAge,
|
||||
false,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.LazyLoading.Set(cacheName, cache)
|
||||
go cacheCleaner(cache)
|
||||
return cache, nil
|
||||
*/
|
||||
}
|
||||
|
||||
func (c Caches) StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string) {
|
||||
/*
|
||||
cache, err := c.lazyLoadCacheForUser(device)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cacheKey := fmt.Sprintf("%s/%s/%s/%s", device.UserID, device.ID, roomID, userID)
|
||||
cache.Set(cacheKey, eventID)
|
||||
*/
|
||||
c.LazyLoading.Set(lazyLoadingCacheKey{
|
||||
UserID: device.UserID,
|
||||
DeviceID: device.ID,
|
||||
RoomID: roomID,
|
||||
TargetUserID: userID,
|
||||
}, eventID)
|
||||
}
|
||||
|
||||
func (c Caches) IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool) {
|
||||
return "", false
|
||||
/*
|
||||
cache, err := c.lazyLoadCacheForUser(device)
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
|
||||
cacheKey := fmt.Sprintf("%s/%s/%s/%s", device.UserID, device.ID, roomID, userID)
|
||||
val, ok := cache.Get(cacheKey)
|
||||
if !ok {
|
||||
return "", ok
|
||||
}
|
||||
return val.(string), ok
|
||||
*/
|
||||
return c.LazyLoading.Get(lazyLoadingCacheKey{
|
||||
UserID: device.UserID,
|
||||
DeviceID: device.ID,
|
||||
RoomID: roomID,
|
||||
TargetUserID: userID,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ type Caches struct {
|
|||
FederationPDUs Cache[int64, *gomatrixserverlib.HeaderedEvent]
|
||||
FederationEDUs Cache[int64, *gomatrixserverlib.EDU]
|
||||
SpaceSummaryRooms Cache[string, gomatrixserverlib.MSC2946SpacesResponse]
|
||||
LazyLoading Cache[string, any]
|
||||
LazyLoading Cache[lazyLoadingCacheKey, string]
|
||||
}
|
||||
|
||||
// Cache is the interface that an implementation must satisfy.
|
||||
|
|
@ -30,7 +30,7 @@ type Cache[K keyable, T any] interface {
|
|||
|
||||
type keyable interface {
|
||||
// from https://github.com/dgraph-io/ristretto/blob/8e850b710d6df0383c375ec6a7beae4ce48fc8d5/z/z.go#L34
|
||||
uint64 | string | []byte | byte | int | int32 | uint32 | int64
|
||||
uint64 | string | []byte | byte | int | int32 | uint32 | int64 | lazyLoadingCacheKey
|
||||
}
|
||||
|
||||
type costable interface {
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enableProm
|
|||
Mutable: true,
|
||||
MaxAge: maxAge,
|
||||
},
|
||||
LazyLoading: &RistrettoCachePartition[string, any]{ // TODO: type
|
||||
LazyLoading: &RistrettoCachePartition[lazyLoadingCacheKey, string]{
|
||||
cache: cache,
|
||||
Prefix: lazyLoadingCache,
|
||||
Mutable: true,
|
||||
|
|
|
|||
Loading…
Reference in a new issue