mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
More flexible caching (#1101)
This commit is contained in:
parent
76ff47c052
commit
e7b19d2c70
16 changed files with 189 additions and 142 deletions
|
@ -16,7 +16,7 @@ type RoomserverInternalAPI struct {
|
|||
DB storage.Database
|
||||
Cfg *config.Dendrite
|
||||
Producer sarama.SyncProducer
|
||||
ImmutableCache caching.ImmutableCache
|
||||
Cache caching.RoomVersionCache
|
||||
ServerName gomatrixserverlib.ServerName
|
||||
KeyRing gomatrixserverlib.JSONVerifier
|
||||
FedClient *gomatrixserverlib.FederationClient
|
||||
|
|
|
@ -951,7 +951,7 @@ func (r *RoomserverInternalAPI) QueryRoomVersionForRoom(
|
|||
request *api.QueryRoomVersionForRoomRequest,
|
||||
response *api.QueryRoomVersionForRoomResponse,
|
||||
) error {
|
||||
if roomVersion, ok := r.ImmutableCache.GetRoomVersion(request.RoomID); ok {
|
||||
if roomVersion, ok := r.Cache.GetRoomVersion(request.RoomID); ok {
|
||||
response.RoomVersion = roomVersion
|
||||
return nil
|
||||
}
|
||||
|
@ -961,6 +961,6 @@ func (r *RoomserverInternalAPI) QueryRoomVersionForRoom(
|
|||
return err
|
||||
}
|
||||
response.RoomVersion = roomVersion
|
||||
r.ImmutableCache.StoreRoomVersion(request.RoomID, response.RoomVersion)
|
||||
r.Cache.StoreRoomVersion(request.RoomID, response.RoomVersion)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -43,9 +43,9 @@ const (
|
|||
)
|
||||
|
||||
type httpRoomserverInternalAPI struct {
|
||||
roomserverURL string
|
||||
httpClient *http.Client
|
||||
immutableCache caching.ImmutableCache
|
||||
roomserverURL string
|
||||
httpClient *http.Client
|
||||
cache caching.RoomVersionCache
|
||||
}
|
||||
|
||||
// NewRoomserverClient creates a RoomserverInputAPI implemented by talking to a HTTP POST API.
|
||||
|
@ -53,15 +53,15 @@ type httpRoomserverInternalAPI struct {
|
|||
func NewRoomserverClient(
|
||||
roomserverURL string,
|
||||
httpClient *http.Client,
|
||||
immutableCache caching.ImmutableCache,
|
||||
cache caching.RoomVersionCache,
|
||||
) (api.RoomserverInternalAPI, error) {
|
||||
if httpClient == nil {
|
||||
return nil, errors.New("NewRoomserverInternalAPIHTTP: httpClient is <nil>")
|
||||
}
|
||||
return &httpRoomserverInternalAPI{
|
||||
roomserverURL: roomserverURL,
|
||||
httpClient: httpClient,
|
||||
immutableCache: immutableCache,
|
||||
roomserverURL: roomserverURL,
|
||||
httpClient: httpClient,
|
||||
cache: cache,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -320,7 +320,7 @@ func (h *httpRoomserverInternalAPI) QueryRoomVersionForRoom(
|
|||
request *api.QueryRoomVersionForRoomRequest,
|
||||
response *api.QueryRoomVersionForRoomResponse,
|
||||
) error {
|
||||
if roomVersion, ok := h.immutableCache.GetRoomVersion(request.RoomID); ok {
|
||||
if roomVersion, ok := h.cache.GetRoomVersion(request.RoomID); ok {
|
||||
response.RoomVersion = roomVersion
|
||||
return nil
|
||||
}
|
||||
|
@ -331,7 +331,7 @@ func (h *httpRoomserverInternalAPI) QueryRoomVersionForRoom(
|
|||
apiURL := h.roomserverURL + RoomserverQueryRoomVersionForRoomPath
|
||||
err := internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
if err == nil {
|
||||
h.immutableCache.StoreRoomVersion(request.RoomID, response.RoomVersion)
|
||||
h.cache.StoreRoomVersion(request.RoomID, response.RoomVersion)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func SetupRoomServerComponent(
|
|||
Cfg: base.Cfg,
|
||||
Producer: base.KafkaProducer,
|
||||
OutputRoomEventTopic: string(base.Cfg.Kafka.Topics.OutputRoomEvent),
|
||||
ImmutableCache: base.ImmutableCache,
|
||||
Cache: base.Caches,
|
||||
ServerName: base.Cfg.Matrix.ServerName,
|
||||
FedClient: fedClient,
|
||||
KeyRing: keyRing,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue