Fix internal cache stuff again

This commit is contained in:
Neil Alexander 2020-06-16 12:11:51 +01:00
parent aae7c86fda
commit 5e609796c9
4 changed files with 16 additions and 11 deletions

View file

@ -255,7 +255,7 @@ func testRoomserver(input []string, wantOutput []string, checkQueries func(api.R
panic(err) panic(err)
} }
cache, err := caching.NewInMemoryLRUCache() cache, err := caching.NewInMemoryLRUCache(false)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View file

@ -8,11 +8,12 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promauto"
) )
func NewInMemoryLRUCache() (*Caches, error) { func NewInMemoryLRUCache(enablePrometheus bool) (*Caches, error) {
roomVersions, err := NewInMemoryLRUCachePartition( roomVersions, err := NewInMemoryLRUCachePartition(
RoomVersionCacheName, RoomVersionCacheName,
RoomVersionCacheMutable, RoomVersionCacheMutable,
RoomVersionCacheMaxEntries, RoomVersionCacheMaxEntries,
enablePrometheus,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -21,6 +22,7 @@ func NewInMemoryLRUCache() (*Caches, error) {
ServerKeyCacheName, ServerKeyCacheName,
ServerKeyCacheMutable, ServerKeyCacheMutable,
ServerKeyCacheMaxEntries, ServerKeyCacheMaxEntries,
enablePrometheus,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -38,7 +40,7 @@ type InMemoryLRUCachePartition struct {
lru *lru.Cache lru *lru.Cache
} }
func NewInMemoryLRUCachePartition(name string, mutable bool, maxEntries int) (*InMemoryLRUCachePartition, error) { func NewInMemoryLRUCachePartition(name string, mutable bool, maxEntries int, enablePrometheus bool) (*InMemoryLRUCachePartition, error) {
var err error var err error
cache := InMemoryLRUCachePartition{ cache := InMemoryLRUCachePartition{
name: name, name: name,
@ -49,6 +51,7 @@ func NewInMemoryLRUCachePartition(name string, mutable bool, maxEntries int) (*I
if err != nil { if err != nil {
return nil, err return nil, err
} }
if enablePrometheus {
promauto.NewGaugeFunc(prometheus.GaugeOpts{ promauto.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "dendrite", Namespace: "dendrite",
Subsystem: "caching_in_memory_lru", Subsystem: "caching_in_memory_lru",
@ -56,6 +59,7 @@ func NewInMemoryLRUCachePartition(name string, mutable bool, maxEntries int) (*I
}, func() float64 { }, func() float64 {
return float64(cache.lru.Len()) return float64(cache.lru.Len())
}) })
}
return &cache, nil return &cache, nil
} }

View file

@ -96,7 +96,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, useHTTPAPIs boo
kafkaConsumer, kafkaProducer = setupKafka(cfg) kafkaConsumer, kafkaProducer = setupKafka(cfg)
} }
cache, err := caching.NewInMemoryLRUCache() cache, err := caching.NewInMemoryLRUCache(true)
if err != nil { if err != nil {
logrus.WithError(err).Warnf("Failed to create cache") logrus.WithError(err).Warnf("Failed to create cache")
} }

View file

@ -21,6 +21,7 @@ import (
type server struct { type server struct {
name gomatrixserverlib.ServerName name gomatrixserverlib.ServerName
validity time.Duration
config *config.Dendrite config *config.Dendrite
fedclient *gomatrixserverlib.FederationClient fedclient *gomatrixserverlib.FederationClient
cache *caching.Caches cache *caching.Caches