2022-04-19 09:46:45 +01:00
|
|
|
package caching
|
|
|
|
|
|
|
|
import (
|
|
|
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
|
|
|
)
|
|
|
|
|
2022-07-11 14:31:31 +01:00
|
|
|
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
|
|
|
|
}
|
2022-04-19 09:46:45 +01:00
|
|
|
|
2022-05-06 14:33:34 +01:00
|
|
|
type LazyLoadCache interface {
|
|
|
|
StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string)
|
|
|
|
IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool)
|
2022-08-05 13:27:27 +01:00
|
|
|
InvalidateLazyLoadedUser(device *userapi.Device, roomID, userID string)
|
2022-04-19 09:46:45 +01:00
|
|
|
}
|
|
|
|
|
2022-05-06 14:33:34 +01:00
|
|
|
func (c Caches) StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string) {
|
2022-07-11 14:31:31 +01:00
|
|
|
c.LazyLoading.Set(lazyLoadingCacheKey{
|
|
|
|
UserID: device.UserID,
|
|
|
|
DeviceID: device.ID,
|
|
|
|
RoomID: roomID,
|
|
|
|
TargetUserID: userID,
|
|
|
|
}, eventID)
|
2022-04-19 09:46:45 +01:00
|
|
|
}
|
|
|
|
|
2022-05-06 14:33:34 +01:00
|
|
|
func (c Caches) IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool) {
|
2022-07-11 14:31:31 +01:00
|
|
|
return c.LazyLoading.Get(lazyLoadingCacheKey{
|
|
|
|
UserID: device.UserID,
|
|
|
|
DeviceID: device.ID,
|
|
|
|
RoomID: roomID,
|
|
|
|
TargetUserID: userID,
|
|
|
|
})
|
2022-04-19 09:46:45 +01:00
|
|
|
}
|
2022-08-05 13:27:27 +01:00
|
|
|
|
|
|
|
func (c Caches) InvalidateLazyLoadedUser(device *userapi.Device, roomID, userID string) {
|
|
|
|
c.LazyLoading.Unset(lazyLoadingCacheKey{
|
|
|
|
UserID: device.UserID,
|
|
|
|
DeviceID: device.ID,
|
|
|
|
RoomID: roomID,
|
|
|
|
TargetUserID: userID,
|
|
|
|
})
|
|
|
|
}
|