aboutsummaryrefslogtreecommitdiff
path: root/internal/caching/impl_inmemorylru.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/caching/impl_inmemorylru.go')
-rw-r--r--internal/caching/impl_inmemorylru.go22
1 files changed, 13 insertions, 9 deletions
diff --git a/internal/caching/impl_inmemorylru.go b/internal/caching/impl_inmemorylru.go
index 158deca4..7bb791dd 100644
--- a/internal/caching/impl_inmemorylru.go
+++ b/internal/caching/impl_inmemorylru.go
@@ -8,11 +8,12 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
)
-func NewInMemoryLRUCache() (*Caches, error) {
+func NewInMemoryLRUCache(enablePrometheus bool) (*Caches, error) {
roomVersions, err := NewInMemoryLRUCachePartition(
RoomVersionCacheName,
RoomVersionCacheMutable,
RoomVersionCacheMaxEntries,
+ enablePrometheus,
)
if err != nil {
return nil, err
@@ -21,6 +22,7 @@ func NewInMemoryLRUCache() (*Caches, error) {
ServerKeyCacheName,
ServerKeyCacheMutable,
ServerKeyCacheMaxEntries,
+ enablePrometheus,
)
if err != nil {
return nil, err
@@ -38,7 +40,7 @@ type InMemoryLRUCachePartition struct {
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
cache := InMemoryLRUCachePartition{
name: name,
@@ -49,13 +51,15 @@ func NewInMemoryLRUCachePartition(name string, mutable bool, maxEntries int) (*I
if err != nil {
return nil, err
}
- promauto.NewGaugeFunc(prometheus.GaugeOpts{
- Namespace: "dendrite",
- Subsystem: "caching_in_memory_lru",
- Name: name,
- }, func() float64 {
- return float64(cache.lru.Len())
- })
+ if enablePrometheus {
+ promauto.NewGaugeFunc(prometheus.GaugeOpts{
+ Namespace: "dendrite",
+ Subsystem: "caching_in_memory_lru",
+ Name: name,
+ }, func() float64 {
+ return float64(cache.lru.Len())
+ })
+ }
return &cache, nil
}