From 1373929ffc5f412d70ac26eaa67069b893b67de9 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 22 Apr 2020 12:23:08 +0100 Subject: [PATCH] Review comments --- common/caching/immutablecache.go | 1 - common/caching/immutableinmemorylru.go | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common/caching/immutablecache.go b/common/caching/immutablecache.go index 9b967f3f6..9620667a2 100644 --- a/common/caching/immutablecache.go +++ b/common/caching/immutablecache.go @@ -3,7 +3,6 @@ package caching import "github.com/matrix-org/gomatrixserverlib" const ( - RoomVersionCachingEnabled = true RoomVersionMaxCacheEntries = 128 ) diff --git a/common/caching/immutableinmemorylru.go b/common/caching/immutableinmemorylru.go index 1d43a267c..fdaff1020 100644 --- a/common/caching/immutableinmemorylru.go +++ b/common/caching/immutableinmemorylru.go @@ -1,6 +1,8 @@ package caching import ( + "fmt" + lru "github.com/hashicorp/golang-lru" "github.com/matrix-org/gomatrixserverlib" ) @@ -21,12 +23,12 @@ func NewImmutableInMemoryLRUCache() (*ImmutableInMemoryLRUCache, error) { func checkForInvalidMutation(cache *lru.Cache, key string, value interface{}) { if peek, ok := cache.Peek(key); ok && peek != value { - panic("invalid use of immutable cache tries to mutate existing value") + panic(fmt.Sprintf("invalid use of immutable cache tries to mutate existing value of %q", key)) } } func (c *ImmutableInMemoryLRUCache) GetRoomVersion(roomID string) (gomatrixserverlib.RoomVersion, bool) { - if c == nil || !RoomVersionCachingEnabled { + if c == nil { return "", false } val, found := c.roomVersions.Get(roomID) @@ -39,7 +41,7 @@ func (c *ImmutableInMemoryLRUCache) GetRoomVersion(roomID string) (gomatrixserve } func (c *ImmutableInMemoryLRUCache) StoreRoomVersion(roomID string, roomVersion gomatrixserverlib.RoomVersion) { - if c == nil || !RoomVersionCachingEnabled { + if c == nil { return } checkForInvalidMutation(c.roomVersions, roomID, roomVersion)