diff --git a/packages/datastructure/lru_cache.go b/packages/datastructure/lru_cache.go index f70a86aee5e75493a0b9259e6a1de2cf66900333..3956eb1e1f8985878615a61adcbf5bbc975836bf 100644 --- a/packages/datastructure/lru_cache.go +++ b/packages/datastructure/lru_cache.go @@ -168,9 +168,9 @@ func (cache *LRUCache) Contains(key interface{}) (result bool) { keyMutex.RLock() cache.mutex.RLock() if element, exists := cache.directory[key]; exists { + cache.mutex.RUnlock() keyMutex.RUnlock() - cache.mutex.RUnlock() cache.mutex.Lock() cache.promoteElement(element) cache.mutex.Unlock() @@ -201,11 +201,11 @@ func (cache *LRUCache) Get(key interface{}) (result interface{}) { result = element.GetValue().(*lruCacheElement).value - keyMutex.RUnlock() } else { cache.mutex.RUnlock() } + keyMutex.RUnlock() cache.krwMutex.Free(key) return @@ -243,6 +243,7 @@ func (cache *LRUCache) Delete(key interface{}) bool { delete(cache.directory, key) cache.size-- + keyMutex.Unlock() if cache.options.EvictionCallback != nil { cache.options.EvictionCallback(key, entry.GetValue().(*lruCacheElement).key)