aboutsummaryrefslogtreecommitdiff
path: root/internal/caching/cache_roomservernids.go
blob: 6d413093f146dacc2e6551ba48daffdec778d274 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package caching

import (
	"strconv"

	"github.com/matrix-org/dendrite/roomserver/types"
)

const (
	RoomServerRoomIDsCacheName       = "roomserver_room_ids"
	RoomServerRoomIDsCacheMaxEntries = 1024
	RoomServerRoomIDsCacheMutable    = false
)

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)
}