0
0
Fork 0
mirror of https://github.com/matrix-org/dendrite synced 2024-12-15 15:23:44 +01:00
dendrite/internal/caching/cache_roomservernids.go
Neil Alexander bb2380c254
Allow specifying max age for caches (#2239)
* Allow specifying max age for caches

* Evict cache entry if it's found to be stale when we call Get

* Fix bugs
2022-03-01 16:59:52 +00:00

41 lines
1 KiB
Go

package caching
import (
"strconv"
"github.com/matrix-org/dendrite/roomserver/types"
)
const (
RoomServerRoomIDsCacheName = "roomserver_room_ids"
RoomServerRoomIDsCacheMaxEntries = 1024
RoomServerRoomIDsCacheMutable = false
RoomServerRoomIDsCacheMaxAge = CacheNoMaxAge
)
type RoomServerCaches interface {
RoomServerNIDsCache
RoomVersionCache
RoomInfoCache
}
// 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) {
val, found := c.RoomServerRoomIDs.Get(strconv.Itoa(int(roomNID)))
if found && val != nil {
if roomID, ok := val.(string); ok {
return roomID, true
}
}
return "", false
}
func (c Caches) StoreRoomServerRoomID(roomNID types.RoomNID, roomID string) {
c.RoomServerRoomIDs.Set(strconv.Itoa(int(roomNID)), roomID)
}