mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Review comments
This commit is contained in:
parent
243081831a
commit
1373929ffc
|
|
@ -3,7 +3,6 @@ package caching
|
||||||
import "github.com/matrix-org/gomatrixserverlib"
|
import "github.com/matrix-org/gomatrixserverlib"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RoomVersionCachingEnabled = true
|
|
||||||
RoomVersionMaxCacheEntries = 128
|
RoomVersionMaxCacheEntries = 128
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package caching
|
package caching
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
@ -21,12 +23,12 @@ func NewImmutableInMemoryLRUCache() (*ImmutableInMemoryLRUCache, error) {
|
||||||
|
|
||||||
func checkForInvalidMutation(cache *lru.Cache, key string, value interface{}) {
|
func checkForInvalidMutation(cache *lru.Cache, key string, value interface{}) {
|
||||||
if peek, ok := cache.Peek(key); ok && peek != value {
|
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) {
|
func (c *ImmutableInMemoryLRUCache) GetRoomVersion(roomID string) (gomatrixserverlib.RoomVersion, bool) {
|
||||||
if c == nil || !RoomVersionCachingEnabled {
|
if c == nil {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
val, found := c.roomVersions.Get(roomID)
|
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) {
|
func (c *ImmutableInMemoryLRUCache) StoreRoomVersion(roomID string, roomVersion gomatrixserverlib.RoomVersion) {
|
||||||
if c == nil || !RoomVersionCachingEnabled {
|
if c == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
checkForInvalidMutation(c.roomVersions, roomID, roomVersion)
|
checkForInvalidMutation(c.roomVersions, roomID, roomVersion)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue