From cfee085119e548df330df9aaddd8703bb67249f1 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 16 Dec 2020 11:08:28 +0000 Subject: [PATCH] LRU package is already threadsafe --- internal/caching/impl_inmemorylru.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/internal/caching/impl_inmemorylru.go b/internal/caching/impl_inmemorylru.go index c060f625d..cf05a8b55 100644 --- a/internal/caching/impl_inmemorylru.go +++ b/internal/caching/impl_inmemorylru.go @@ -2,7 +2,6 @@ package caching import ( "fmt" - "sync" lru "github.com/hashicorp/golang-lru" "github.com/prometheus/client_golang/prometheus" @@ -88,7 +87,6 @@ type InMemoryLRUCachePartition struct { name string mutable bool maxEntries int - mutex sync.RWMutex lru *lru.Cache } @@ -116,8 +114,6 @@ func NewInMemoryLRUCachePartition(name string, mutable bool, maxEntries int, ena } func (c *InMemoryLRUCachePartition) Set(key string, value interface{}) { - c.mutex.Lock() - defer c.mutex.Unlock() if !c.mutable { 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)) @@ -127,8 +123,6 @@ func (c *InMemoryLRUCachePartition) Set(key string, value interface{}) { } func (c *InMemoryLRUCachePartition) Unset(key string) { - c.mutex.Lock() - defer c.mutex.Unlock() if !c.mutable { 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) { - c.mutex.RLock() - defer c.mutex.RUnlock() return c.lru.Get(key) }