2022-03-01 16:32:48 +00:00
|
|
|
package caching
|
|
|
|
|
2022-03-01 17:01:08 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
|
|
|
)
|
2022-03-01 16:32:48 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
SpaceSummaryRoomsCacheName = "space_summary_rooms"
|
|
|
|
SpaceSummaryRoomsCacheMaxEntries = 100
|
|
|
|
SpaceSummaryRoomsCacheMutable = true
|
2022-03-01 17:01:08 +00:00
|
|
|
SpaceSummaryRoomsCacheMaxAge = time.Minute * 5
|
2022-03-01 16:32:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type SpaceSummaryRoomsCache interface {
|
|
|
|
GetSpaceSummary(roomID string) (r gomatrixserverlib.MSC2946SpacesResponse, ok bool)
|
|
|
|
StoreSpaceSummary(roomID string, r gomatrixserverlib.MSC2946SpacesResponse)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Caches) GetSpaceSummary(roomID string) (r gomatrixserverlib.MSC2946SpacesResponse, ok bool) {
|
|
|
|
val, found := c.SpaceSummaryRooms.Get(roomID)
|
|
|
|
if found && val != nil {
|
|
|
|
if resp, ok := val.(gomatrixserverlib.MSC2946SpacesResponse); ok {
|
|
|
|
return resp, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r, false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Caches) StoreSpaceSummary(roomID string, r gomatrixserverlib.MSC2946SpacesResponse) {
|
|
|
|
c.SpaceSummaryRooms.Set(roomID, r)
|
|
|
|
}
|