Documentation ¶
Index ¶
- Constants
- type Cache
- type Caches
- func (c Caches) EvictFederationQueuedEDU(ctx context.Context, eventNID int64) error
- func (c Caches) EvictFederationQueuedPDU(ctx context.Context, eventNID int64) error
- func (c Caches) GetEventStateKey(ctx context.Context, eventStateKeyNID types.EventStateKeyNID) (string, bool)
- func (c Caches) GetEventStateKeyNID(ctx context.Context, eventStateKey string) (types.EventStateKeyNID, bool)
- func (c Caches) GetEventTypeKey(ctx context.Context, eventType string) (types.EventTypeNID, bool)
- func (c Caches) GetFederationQueuedEDU(ctx context.Context, eventNID int64) (*gomatrixserverlib.EDU, bool)
- func (c Caches) GetFederationQueuedPDU(ctx context.Context, eventNID int64) (*types.HeaderedEvent, bool)
- func (c Caches) GetRoomHierarchy(ctx context.Context, roomID string) (r fclient.RoomHierarchyResponse, ok bool)
- func (c Caches) GetRoomServerEvent(ctx context.Context, eventNID types.EventNID) (*types.HeaderedEvent, bool)
- func (c Caches) GetRoomServerRoomID(ctx context.Context, roomNID types.RoomNID) (string, bool)
- func (c Caches) GetRoomServerRoomNID(ctx context.Context, roomID string) (types.RoomNID, bool)
- func (c Caches) GetRoomVersion(ctx context.Context, roomID string) (gomatrixserverlib.RoomVersion, bool)
- func (c Caches) GetServerKey(ctx context.Context, request gomatrixserverlib.PublicKeyLookupRequest, ...) (gomatrixserverlib.PublicKeyLookupResult, bool)
- func (c Caches) InvalidateLazyLoadedUser(ctx context.Context, device *userapi.Device, roomID, userID string) error
- func (c Caches) InvalidateRoomServerEvent(ctx context.Context, eventNID types.EventNID) error
- func (c Caches) IsLazyLoadedUserCached(ctx context.Context, device *userapi.Device, roomID, userID string) (string, bool)
- func (c Caches) StoreEventStateKey(ctx context.Context, eventStateKeyNID types.EventStateKeyNID, ...) error
- func (c Caches) StoreEventTypeKey(ctx context.Context, eventTypeNID types.EventTypeNID, eventType string) error
- func (c Caches) StoreFederationQueuedEDU(ctx context.Context, eventNID int64, event *gomatrixserverlib.EDU) error
- func (c Caches) StoreFederationQueuedPDU(ctx context.Context, eventNID int64, event *types.HeaderedEvent) error
- func (c Caches) StoreLazyLoadedUser(ctx context.Context, device *userapi.Device, roomID, userID, eventID string) error
- func (c Caches) StoreRoomHierarchy(ctx context.Context, roomID string, r fclient.RoomHierarchyResponse) error
- func (c Caches) StoreRoomServerEvent(ctx context.Context, eventNID types.EventNID, event *types.HeaderedEvent) error
- func (c Caches) StoreRoomServerRoomID(ctx context.Context, roomNID types.RoomNID, roomID string) error
- func (c Caches) StoreRoomVersion(ctx context.Context, roomID string, roomVersion gomatrixserverlib.RoomVersion) error
- func (c Caches) StoreServerKey(ctx context.Context, request gomatrixserverlib.PublicKeyLookupRequest, ...) error
- type EDUCache
- func (t *EDUCache) AddTypingUser(userID, roomID string, expire *time.Time) int64
- func (t *EDUCache) GetLatestSyncPosition() int64
- func (t *EDUCache) GetTypingUsers(roomID string) []string
- func (t *EDUCache) GetTypingUsersIfUpdatedAfter(roomID string, position int64) (users []string, updated bool)
- func (t *EDUCache) RemoveUser(userID, roomID string) int64
- func (t *EDUCache) SetTimeoutCallback(fn TimeoutCallbackFn)
- type EventStateKeyCache
- type EventTypeCache
- type FederationCache
- type LazyLoadCache
- type RedisCachePartition
- type RistrettoCachePartition
- type RistrettoCostedCachePartition
- type RoomHierarchyCache
- type RoomServerCaches
- type RoomServerEventsCache
- type RoomServerNIDsCache
- type RoomVersionCache
- type ServerKeyCache
- type TimeoutCallbackFn
Constants ¶
const ( DisableMetrics = false EnableMetrics = true )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K keyable, T any] interface { Get(ctx context.Context, key K) (value T, ok bool) Set(ctx context.Context, key K, value T) error Unset(ctx context.Context, key K) error }
Cache is the interface that an implementation must satisfy.
type Caches ¶
type Caches struct { 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, *types.HeaderedEvent] // 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, *types.HeaderedEvent] // queue NID -> PDU FederationEDUs Cache[int64, *gomatrixserverlib.EDU] // queue NID -> EDU RoomHierarchies Cache[string, fclient.RoomHierarchyResponse] // room ID -> space response LazyLoading Cache[lazyLoadingCacheKey, string] // composite key -> event ID }
Caches contains a set of references to caches. They may be different implementations as long as they satisfy the Cache interface.
func NewCache ¶ added in v0.1.3
func NewCache(cfg *config.CacheOptions) *Caches
func NewRedisCache ¶ added in v0.1.3
NewRedisCache Main Redis-based caching setup
func NewRistrettoCache ¶
func (Caches) EvictFederationQueuedEDU ¶
func (Caches) EvictFederationQueuedPDU ¶
func (Caches) GetEventStateKey ¶
func (Caches) GetEventStateKeyNID ¶
func (Caches) GetEventTypeKey ¶
func (Caches) GetFederationQueuedEDU ¶
func (Caches) GetFederationQueuedPDU ¶
func (Caches) GetRoomHierarchy ¶
func (Caches) GetRoomServerEvent ¶
func (Caches) GetRoomServerRoomID ¶
func (Caches) GetRoomServerRoomNID ¶
func (Caches) GetRoomVersion ¶
func (c Caches) GetRoomVersion(ctx context.Context, roomID string) (gomatrixserverlib.RoomVersion, bool)
func (Caches) GetServerKey ¶
func (c Caches) GetServerKey( ctx context.Context, request gomatrixserverlib.PublicKeyLookupRequest, timestamp spec.Timestamp, ) (gomatrixserverlib.PublicKeyLookupResult, bool)
func (Caches) InvalidateLazyLoadedUser ¶
func (Caches) InvalidateRoomServerEvent ¶
func (Caches) IsLazyLoadedUserCached ¶
func (Caches) StoreEventStateKey ¶
func (Caches) StoreEventTypeKey ¶
func (Caches) StoreFederationQueuedEDU ¶
func (Caches) StoreFederationQueuedPDU ¶
func (Caches) StoreLazyLoadedUser ¶
func (Caches) StoreRoomHierarchy ¶
func (Caches) StoreRoomServerEvent ¶
func (Caches) StoreRoomServerRoomID ¶
func (c Caches) StoreRoomServerRoomID(ctx context.Context, roomNID types.RoomNID, roomID string) error
StoreRoomServerRoomID stores roomNID -> roomID and roomID -> roomNID
func (Caches) StoreRoomVersion ¶
func (c Caches) StoreRoomVersion(ctx context.Context, roomID string, roomVersion gomatrixserverlib.RoomVersion) error
func (Caches) StoreServerKey ¶
func (c Caches) StoreServerKey( ctx context.Context, request gomatrixserverlib.PublicKeyLookupRequest, response gomatrixserverlib.PublicKeyLookupResult, ) error
type EDUCache ¶
EDUCache maintains a list of users typing in each room.
func NewTypingCache ¶
func NewTypingCache() *EDUCache
NewTypingCache returns a new EDUCache initialised for use.
func (*EDUCache) AddTypingUser ¶
AddTypingUser sets an user as typing in a room. expire is the time when the user typing should time out. if expire is nil, defaultTypingTimeout is assumed. Returns the latest sync position for typing after update.
func (*EDUCache) GetLatestSyncPosition ¶
func (*EDUCache) GetTypingUsers ¶
GetTypingUsers returns the list of users typing in a room.
func (*EDUCache) GetTypingUsersIfUpdatedAfter ¶
func (t *EDUCache) GetTypingUsersIfUpdatedAfter( roomID string, position int64, ) (users []string, updated bool)
GetTypingUsersIfUpdatedAfter returns all users typing in this room with updated == true if the typing sync position of the room is after the given position. Otherwise, returns an empty slice with updated == false.
func (*EDUCache) RemoveUser ¶
RemoveUser with mutex lock & stop the timer. Returns the latest sync position for typing after update.
func (*EDUCache) SetTimeoutCallback ¶
func (t *EDUCache) SetTimeoutCallback(fn TimeoutCallbackFn)
SetTimeoutCallback sets a callback function that is called right after a user is removed from the typing user list due to timeout.
type EventStateKeyCache ¶
type EventStateKeyCache interface { GetEventStateKey(ctx context.Context, eventStateKeyNID types.EventStateKeyNID) (string, bool) StoreEventStateKey(ctx context.Context, eventStateKeyNID types.EventStateKeyNID, eventStateKey string) error GetEventStateKeyNID(ctx context.Context, eventStateKey string) (types.EventStateKeyNID, bool) }
EventStateKeyCache contains the subset of functions needed for a room event state key cache.
type EventTypeCache ¶
type FederationCache ¶
type FederationCache interface { GetFederationQueuedPDU(ctx context.Context, eventNID int64) (event *types.HeaderedEvent, ok bool) StoreFederationQueuedPDU(ctx context.Context, eventNID int64, event *types.HeaderedEvent) error EvictFederationQueuedPDU(ctx context.Context, eventNID int64) error GetFederationQueuedEDU(ctx context.Context, eventNID int64) (event *gomatrixserverlib.EDU, ok bool) StoreFederationQueuedEDU(ctx context.Context, eventNID int64, event *gomatrixserverlib.EDU) error EvictFederationQueuedEDU(ctx context.Context, eventNID int64) error }
FederationCache contains the subset of functions needed for a federation event cache.
type LazyLoadCache ¶
type LazyLoadCache interface { StoreLazyLoadedUser(ctx context.Context, device *userapi.Device, roomID, userID, eventID string) error IsLazyLoadedUserCached(ctx context.Context, device *userapi.Device, roomID, userID string) (string, bool) InvalidateLazyLoadedUser(ctx context.Context, device *userapi.Device, roomID, userID string) error }
type RedisCachePartition ¶ added in v0.1.3
type RedisCachePartition[K comparable, V any] struct { Prefix byte Mutable bool MaxAge time.Duration // contains filtered or unexported fields }
RedisCachePartition Define the RedisCachePartition type to replace Ristretto
func (*RedisCachePartition[K, V]) Get ¶ added in v0.1.3
func (c *RedisCachePartition[K, V]) Get(ctx context.Context, key K) (V, bool)
Get value from Redis with JSON deserialisation
type RistrettoCachePartition ¶
type RistrettoCachePartition[K keyable, V any] struct { Prefix byte Mutable bool MaxAge time.Duration // contains filtered or unexported fields }
func (*RistrettoCachePartition[K, V]) Get ¶
func (c *RistrettoCachePartition[K, V]) Get(_ context.Context, key K) (value V, ok bool)
type RistrettoCostedCachePartition ¶
type RistrettoCostedCachePartition[k keyable, v costable] struct { *RistrettoCachePartition[k, v] }
type RoomHierarchyCache ¶
type RoomHierarchyCache interface { GetRoomHierarchy(ctx context.Context, roomID string) (r fclient.RoomHierarchyResponse, ok bool) StoreRoomHierarchy(ctx context.Context, roomID string, r fclient.RoomHierarchyResponse) error }
RoomHierarchy cache caches responses to federated room hierarchy requests (A.K.A. 'space summaries')
type RoomServerCaches ¶
type RoomServerCaches interface { RoomServerNIDsCache RoomVersionCache RoomServerEventsCache RoomHierarchyCache EventStateKeyCache EventTypeCache }
type RoomServerEventsCache ¶
type RoomServerEventsCache interface { GetRoomServerEvent(ctx context.Context, eventNID types.EventNID) (*types.HeaderedEvent, bool) StoreRoomServerEvent(ctx context.Context, eventNID types.EventNID, event *types.HeaderedEvent) error InvalidateRoomServerEvent(ctx context.Context, eventNID types.EventNID) error }
RoomServerEventsCache contains the subset of functions needed for a room server event cache.
type RoomServerNIDsCache ¶
type RoomServerNIDsCache interface { GetRoomServerRoomID(ctx context.Context, roomNID types.RoomNID) (string, bool) // StoreRoomServerRoomID stores roomNID -> roomID and roomID -> roomNID StoreRoomServerRoomID(ctx context.Context, roomNID types.RoomNID, roomID string) error GetRoomServerRoomNID(ctx context.Context, roomID string) (types.RoomNID, bool) }
RoomServerNIDsCache contains the subset of functions needed for a roomserver NID cache.
type RoomVersionCache ¶
type RoomVersionCache interface { GetRoomVersion(ctx context.Context, roomID string) (roomVersion gomatrixserverlib.RoomVersion, ok bool) StoreRoomVersion(ctx context.Context, roomID string, roomVersion gomatrixserverlib.RoomVersion) error }
RoomVersionsCache contains the subset of functions needed for a room version cache.
type ServerKeyCache ¶
type ServerKeyCache interface { // request -> timestamp is emulating gomatrixserverlib.FetchKeys: // https://github.com/matrix-org/gomatrixserverlib/blob/f69539c86ea55d1e2cc76fd8e944e2d82d30397c/keyring.go#L95 // The timestamp should be the timestamp of the event that is being // verified. We will not return keys from the cache that are not valid // at this timestamp. GetServerKey(ctx context.Context, request gomatrixserverlib.PublicKeyLookupRequest, timestamp spec.Timestamp) (response gomatrixserverlib.PublicKeyLookupResult, ok bool) // request -> result is emulating gomatrixserverlib.StoreKeys: // https://github.com/matrix-org/gomatrixserverlib/blob/f69539c86ea55d1e2cc76fd8e944e2d82d30397c/keyring.go#L112 StoreServerKey(ctx context.Context, request gomatrixserverlib.PublicKeyLookupRequest, response gomatrixserverlib.PublicKeyLookupResult) error }
ServerKeyCache contains the subset of functions needed for a server key cache.
type TimeoutCallbackFn ¶
TimeoutCallbackFn is a function called right after the removal of a user from the typing user list due to timeout. latestSyncPosition is the typing sync position after the removal.