2022-07-11 08:31:31 -05:00
|
|
|
// Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2020-06-05 10:42:01 -05:00
|
|
|
package caching
|
|
|
|
|
2022-05-06 08:33:34 -05:00
|
|
|
import (
|
2022-07-11 08:31:31 -05:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/types"
|
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2022-05-06 08:33:34 -05:00
|
|
|
)
|
2022-03-01 10:59:52 -06:00
|
|
|
|
2020-06-05 10:42:01 -05:00
|
|
|
// Caches contains a set of references to caches. They may be
|
|
|
|
// different implementations as long as they satisfy the Cache
|
|
|
|
// interface.
|
|
|
|
type Caches struct {
|
2023-02-24 02:40:20 -06:00
|
|
|
RoomVersions Cache[string, gomatrixserverlib.RoomVersion] // room ID -> room version
|
|
|
|
ServerKeys Cache[string, gomatrixserverlib.PublicKeyLookupResult] // server name -> server keys
|
|
|
|
RoomServerRoomNIDs Cache[string, types.RoomNID] // room ID -> room NID
|
|
|
|
RoomServerRoomIDs Cache[types.RoomNID, string] // room NID -> room ID
|
|
|
|
RoomServerEvents Cache[int64, *gomatrixserverlib.Event] // event NID -> event
|
|
|
|
RoomServerStateKeys Cache[types.EventStateKeyNID, string] // eventStateKey NID -> event state key
|
|
|
|
RoomServerStateKeyNIDs Cache[string, types.EventStateKeyNID] // event state key -> eventStateKey NID
|
|
|
|
RoomServerEventTypeNIDs Cache[string, types.EventTypeNID] // eventType -> eventType NID
|
|
|
|
RoomServerEventTypes Cache[types.EventTypeNID, string] // eventType NID -> eventType
|
|
|
|
FederationPDUs Cache[int64, *gomatrixserverlib.HeaderedEvent] // queue NID -> PDU
|
|
|
|
FederationEDUs Cache[int64, *gomatrixserverlib.EDU] // queue NID -> EDU
|
|
|
|
SpaceSummaryRooms Cache[string, gomatrixserverlib.MSC2946SpacesResponse] // room ID -> space response
|
|
|
|
LazyLoading Cache[lazyLoadingCacheKey, string] // composite key -> event ID
|
2020-06-05 10:42:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cache is the interface that an implementation must satisfy.
|
2022-07-11 08:31:31 -05:00
|
|
|
type Cache[K keyable, T any] interface {
|
|
|
|
Get(key K) (value T, ok bool)
|
|
|
|
Set(key K, value T)
|
|
|
|
Unset(key K)
|
|
|
|
}
|
|
|
|
|
|
|
|
type keyable interface {
|
|
|
|
// from https://github.com/dgraph-io/ristretto/blob/8e850b710d6df0383c375ec6a7beae4ce48fc8d5/z/z.go#L34
|
2022-07-19 06:15:48 -05:00
|
|
|
~uint64 | ~string | []byte | byte | ~int | ~int32 | ~uint32 | ~int64 | lazyLoadingCacheKey
|
2020-06-05 10:42:01 -05:00
|
|
|
}
|
2022-03-01 10:59:52 -06:00
|
|
|
|
2022-07-11 08:31:31 -05:00
|
|
|
type costable interface {
|
|
|
|
CacheCost() int
|
|
|
|
}
|