2020-08-25 12:32:29 +01:00
|
|
|
package caching
|
|
|
|
|
|
|
|
import (
|
2020-11-09 18:46:11 +00:00
|
|
|
"strconv"
|
|
|
|
|
2020-08-25 12:32:29 +01:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
RoomServerRoomIDsCacheName = "roomserver_room_ids"
|
|
|
|
RoomServerRoomIDsCacheMaxEntries = 1024
|
|
|
|
RoomServerRoomIDsCacheMutable = false
|
2022-03-01 16:59:52 +00:00
|
|
|
RoomServerRoomIDsCacheMaxAge = CacheNoMaxAge
|
2020-08-25 12:32:29 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type RoomServerCaches interface {
|
|
|
|
RoomServerNIDsCache
|
|
|
|
RoomVersionCache
|
2020-12-16 12:15:12 +00:00
|
|
|
RoomInfoCache
|
2020-08-25 12:32:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// RoomServerNIDsCache contains the subset of functions needed for
|
|
|
|
// a roomserver NID cache.
|
|
|
|
type RoomServerNIDsCache interface {
|
|
|
|
GetRoomServerRoomID(roomNID types.RoomNID) (string, bool)
|
|
|
|
StoreRoomServerRoomID(roomNID types.RoomNID, roomID string)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Caches) GetRoomServerRoomID(roomNID types.RoomNID) (string, bool) {
|
2020-11-09 18:46:11 +00:00
|
|
|
val, found := c.RoomServerRoomIDs.Get(strconv.Itoa(int(roomNID)))
|
2020-08-25 12:32:29 +01:00
|
|
|
if found && val != nil {
|
|
|
|
if roomID, ok := val.(string); ok {
|
|
|
|
return roomID, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Caches) StoreRoomServerRoomID(roomNID types.RoomNID, roomID string) {
|
2020-12-16 12:15:12 +00:00
|
|
|
c.RoomServerRoomIDs.Set(strconv.Itoa(int(roomNID)), roomID)
|
2020-08-25 12:32:29 +01:00
|
|
|
}
|