mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-26 00:03:09 -06:00
LRU package is already threadsafe
This commit is contained in:
parent
14c8fa3deb
commit
cfee085119
|
|
@ -2,7 +2,6 @@ package caching
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
|
||||||
|
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
@ -88,7 +87,6 @@ type InMemoryLRUCachePartition struct {
|
||||||
name string
|
name string
|
||||||
mutable bool
|
mutable bool
|
||||||
maxEntries int
|
maxEntries int
|
||||||
mutex sync.RWMutex
|
|
||||||
lru *lru.Cache
|
lru *lru.Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,8 +114,6 @@ func NewInMemoryLRUCachePartition(name string, mutable bool, maxEntries int, ena
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *InMemoryLRUCachePartition) Set(key string, value interface{}) {
|
func (c *InMemoryLRUCachePartition) Set(key string, value interface{}) {
|
||||||
c.mutex.Lock()
|
|
||||||
defer c.mutex.Unlock()
|
|
||||||
if !c.mutable {
|
if !c.mutable {
|
||||||
if peek, ok := c.lru.Peek(key); ok && peek != value {
|
if peek, ok := c.lru.Peek(key); ok && peek != value {
|
||||||
panic(fmt.Sprintf("invalid use of immutable cache tries to mutate existing value of %q", key))
|
panic(fmt.Sprintf("invalid use of immutable cache tries to mutate existing value of %q", key))
|
||||||
|
|
@ -127,8 +123,6 @@ func (c *InMemoryLRUCachePartition) Set(key string, value interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *InMemoryLRUCachePartition) Unset(key string) {
|
func (c *InMemoryLRUCachePartition) Unset(key string) {
|
||||||
c.mutex.Lock()
|
|
||||||
defer c.mutex.Unlock()
|
|
||||||
if !c.mutable {
|
if !c.mutable {
|
||||||
panic(fmt.Sprintf("invalid use of immutable cache tries to unset value of %q", key))
|
panic(fmt.Sprintf("invalid use of immutable cache tries to unset value of %q", key))
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +130,5 @@ func (c *InMemoryLRUCachePartition) Unset(key string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *InMemoryLRUCachePartition) Get(key string) (value interface{}, ok bool) {
|
func (c *InMemoryLRUCachePartition) Get(key string) (value interface{}, ok bool) {
|
||||||
c.mutex.RLock()
|
|
||||||
defer c.mutex.RUnlock()
|
|
||||||
return c.lru.Get(key)
|
return c.lru.Get(key)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue