caching

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
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(key K) (value T, ok bool)
	Set(key K, value T)
	Unset(key K)
}

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
	SpaceSummaryRooms       Cache[string, fclient.MSC2946SpacesResponse]           // 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 NewRistrettoCache added in v0.9.0

func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enablePrometheus bool) *Caches

func (Caches) EvictFederationQueuedEDU added in v0.6.0

func (c Caches) EvictFederationQueuedEDU(eventNID int64)

func (Caches) EvictFederationQueuedPDU added in v0.6.0

func (c Caches) EvictFederationQueuedPDU(eventNID int64)

func (Caches) GetEventStateKey added in v0.9.0

func (c Caches) GetEventStateKey(eventStateKeyNID types.EventStateKeyNID) (string, bool)

func (Caches) GetEventStateKeyNID added in v0.12.0

func (c Caches) GetEventStateKeyNID(eventStateKey string) (types.EventStateKeyNID, bool)

func (Caches) GetEventTypeKey added in v0.12.0

func (c Caches) GetEventTypeKey(eventType string) (types.EventTypeNID, bool)

func (Caches) GetFederationQueuedEDU added in v0.6.0

func (c Caches) GetFederationQueuedEDU(eventNID int64) (*gomatrixserverlib.EDU, bool)

func (Caches) GetFederationQueuedPDU added in v0.6.0

func (c Caches) GetFederationQueuedPDU(eventNID int64) (*types.HeaderedEvent, bool)

func (Caches) GetRoomServerEvent added in v0.9.0

func (c Caches) GetRoomServerEvent(eventNID types.EventNID) (*types.HeaderedEvent, bool)

func (Caches) GetRoomServerRoomID

func (c Caches) GetRoomServerRoomID(roomNID types.RoomNID) (string, bool)

func (Caches) GetRoomServerRoomNID

func (c Caches) GetRoomServerRoomNID(roomID string) (types.RoomNID, bool)

func (Caches) GetRoomVersion

func (c Caches) GetRoomVersion(roomID string) (gomatrixserverlib.RoomVersion, bool)

func (Caches) GetSpaceSummary added in v0.6.5

func (c Caches) GetSpaceSummary(roomID string) (r fclient.MSC2946SpacesResponse, ok bool)

func (Caches) InvalidateLazyLoadedUser added in v0.9.2

func (c Caches) InvalidateLazyLoadedUser(device *userapi.Device, roomID, userID string)

func (Caches) InvalidateRoomServerEvent added in v0.12.0

func (c Caches) InvalidateRoomServerEvent(eventNID types.EventNID)

func (Caches) IsLazyLoadedUserCached added in v0.8.3

func (c Caches) IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool)

func (Caches) StoreEventStateKey added in v0.9.0

func (c Caches) StoreEventStateKey(eventStateKeyNID types.EventStateKeyNID, eventStateKey string)

func (Caches) StoreEventTypeKey added in v0.12.0

func (c Caches) StoreEventTypeKey(eventTypeNID types.EventTypeNID, eventType string)

func (Caches) StoreFederationQueuedEDU added in v0.6.0

func (c Caches) StoreFederationQueuedEDU(eventNID int64, event *gomatrixserverlib.EDU)

func (Caches) StoreFederationQueuedPDU added in v0.6.0

func (c Caches) StoreFederationQueuedPDU(eventNID int64, event *types.HeaderedEvent)

func (Caches) StoreLazyLoadedUser added in v0.8.3

func (c Caches) StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string)

func (Caches) StoreRoomServerEvent added in v0.9.0

func (c Caches) StoreRoomServerEvent(eventNID types.EventNID, event *types.HeaderedEvent)

func (Caches) StoreRoomServerRoomID

func (c Caches) StoreRoomServerRoomID(roomNID types.RoomNID, roomID string)

StoreRoomServerRoomID stores roomNID -> roomID and roomID -> roomNID

func (Caches) StoreRoomVersion

func (c Caches) StoreRoomVersion(roomID string, roomVersion gomatrixserverlib.RoomVersion)

func (Caches) StoreServerKey

func (Caches) StoreSpaceSummary added in v0.6.5

func (c Caches) StoreSpaceSummary(roomID string, r fclient.MSC2946SpacesResponse)

type EDUCache added in v0.8.0

type EDUCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

EDUCache maintains a list of users typing in each room.

func NewTypingCache added in v0.8.0

func NewTypingCache() *EDUCache

NewTypingCache returns a new EDUCache initialised for use.

func (*EDUCache) AddTypingUser added in v0.8.0

func (t *EDUCache) AddTypingUser(
	userID, roomID string, expire *time.Time,
) int64

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 added in v0.8.0

func (t *EDUCache) GetLatestSyncPosition() int64

func (*EDUCache) GetTypingUsers added in v0.8.0

func (t *EDUCache) GetTypingUsers(roomID string) []string

GetTypingUsers returns the list of users typing in a room.

func (*EDUCache) GetTypingUsersIfUpdatedAfter added in v0.8.0

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 added in v0.8.0

func (t *EDUCache) RemoveUser(userID, roomID string) int64

RemoveUser with mutex lock & stop the timer. Returns the latest sync position for typing after update.

func (*EDUCache) SetTimeoutCallback added in v0.8.0

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 added in v0.9.0

type EventStateKeyCache interface {
	GetEventStateKey(eventStateKeyNID types.EventStateKeyNID) (string, bool)
	StoreEventStateKey(eventStateKeyNID types.EventStateKeyNID, eventStateKey string)
	GetEventStateKeyNID(eventStateKey string) (types.EventStateKeyNID, bool)
}

EventStateKeyCache contains the subset of functions needed for a room event state key cache.

type EventTypeCache added in v0.12.0

type EventTypeCache interface {
	GetEventTypeKey(eventType string) (types.EventTypeNID, bool)
	StoreEventTypeKey(eventTypeNID types.EventTypeNID, eventType string)
}

type FederationCache added in v0.6.0

type FederationCache interface {
	GetFederationQueuedPDU(eventNID int64) (event *types.HeaderedEvent, ok bool)
	StoreFederationQueuedPDU(eventNID int64, event *types.HeaderedEvent)
	EvictFederationQueuedPDU(eventNID int64)

	GetFederationQueuedEDU(eventNID int64) (event *gomatrixserverlib.EDU, ok bool)
	StoreFederationQueuedEDU(eventNID int64, event *gomatrixserverlib.EDU)
	EvictFederationQueuedEDU(eventNID int64)
}

FederationCache contains the subset of functions needed for a federation event cache.

type LazyLoadCache added in v0.8.2

type LazyLoadCache interface {
	StoreLazyLoadedUser(device *userapi.Device, roomID, userID, eventID string)
	IsLazyLoadedUserCached(device *userapi.Device, roomID, userID string) (string, bool)
	InvalidateLazyLoadedUser(device *userapi.Device, roomID, userID string)
}

type RistrettoCachePartition added in v0.9.0

type RistrettoCachePartition[K keyable, V any] struct {
	Prefix  byte
	Mutable bool
	MaxAge  time.Duration
	// contains filtered or unexported fields
}

func (*RistrettoCachePartition[K, V]) Get added in v0.9.0

func (c *RistrettoCachePartition[K, V]) Get(key K) (value V, ok bool)

func (*RistrettoCachePartition[K, V]) Set added in v0.9.0

func (c *RistrettoCachePartition[K, V]) Set(key K, value V)

func (*RistrettoCachePartition[K, V]) Unset added in v0.9.0

func (c *RistrettoCachePartition[K, V]) Unset(key K)

type RistrettoCostedCachePartition added in v0.9.0

type RistrettoCostedCachePartition[k keyable, v costable] struct {
	*RistrettoCachePartition[k, v]
}

func (*RistrettoCostedCachePartition[K, V]) Set added in v0.9.0

func (c *RistrettoCostedCachePartition[K, V]) Set(key K, value V)

type RoomServerEventsCache added in v0.9.0

type RoomServerEventsCache interface {
	GetRoomServerEvent(eventNID types.EventNID) (*types.HeaderedEvent, bool)
	StoreRoomServerEvent(eventNID types.EventNID, event *types.HeaderedEvent)
	InvalidateRoomServerEvent(eventNID types.EventNID)
}

RoomServerEventsCache contains the subset of functions needed for a roomserver event cache.

type RoomServerNIDsCache

type RoomServerNIDsCache interface {
	GetRoomServerRoomID(roomNID types.RoomNID) (string, bool)
	// StoreRoomServerRoomID stores roomNID -> roomID and roomID -> roomNID
	StoreRoomServerRoomID(roomNID types.RoomNID, roomID string)
	GetRoomServerRoomNID(roomID string) (types.RoomNID, bool)
}

RoomServerNIDsCache contains the subset of functions needed for a roomserver NID cache.

type RoomVersionCache

type RoomVersionCache interface {
	GetRoomVersion(roomID string) (roomVersion gomatrixserverlib.RoomVersion, ok bool)
	StoreRoomVersion(roomID string, roomVersion gomatrixserverlib.RoomVersion)
}

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(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(request gomatrixserverlib.PublicKeyLookupRequest, response gomatrixserverlib.PublicKeyLookupResult)
}

ServerKeyCache contains the subset of functions needed for a server key cache.

type SpaceSummaryRoomsCache added in v0.6.5

type SpaceSummaryRoomsCache interface {
	GetSpaceSummary(roomID string) (r fclient.MSC2946SpacesResponse, ok bool)
	StoreSpaceSummary(roomID string, r fclient.MSC2946SpacesResponse)
}

type TimeoutCallbackFn added in v0.8.0

type TimeoutCallbackFn func(userID, roomID string, latestSyncPosition int64)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL