aboutsummaryrefslogtreecommitdiff
path: root/internal/caching/cache_roomversions.go
blob: 92d2eab0806bee833f0597ec90be537c6dc9ade5 (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
package caching

import "github.com/matrix-org/gomatrixserverlib"

const (
	RoomVersionCacheName       = "room_versions"
	RoomVersionCacheMaxEntries = 1024
	RoomVersionCacheMutable    = false
	RoomVersionCacheMaxAge     = CacheNoMaxAge
)

// RoomVersionsCache contains the subset of functions needed for
// a room version cache.
type RoomVersionCache interface {
	GetRoomVersion(roomID string) (roomVersion gomatrixserverlib.RoomVersion, ok bool)
	StoreRoomVersion(roomID string, roomVersion gomatrixserverlib.RoomVersion)
}

func (c Caches) GetRoomVersion(roomID string) (gomatrixserverlib.RoomVersion, bool) {
	val, found := c.RoomVersions.Get(roomID)
	if found && val != nil {
		if roomVersion, ok := val.(gomatrixserverlib.RoomVersion); ok {
			return roomVersion, true
		}
	}
	return "", false
}

func (c Caches) StoreRoomVersion(roomID string, roomVersion gomatrixserverlib.RoomVersion) {
	c.RoomVersions.Set(roomID, roomVersion)
}