Skip to content
Snippets Groups Projects
Unverified Commit e7069df3 authored by Hans Moog's avatar Hans Moog Committed by GitHub
Browse files

Merge pull request #84 from muXxer/lru-fixes

LRU cache bugfixes
parents 383198c0 39aa4917
Branches
Tags
No related merge requests found
...@@ -168,9 +168,9 @@ func (cache *LRUCache) Contains(key interface{}) (result bool) { ...@@ -168,9 +168,9 @@ func (cache *LRUCache) Contains(key interface{}) (result bool) {
keyMutex.RLock() keyMutex.RLock()
cache.mutex.RLock() cache.mutex.RLock()
if element, exists := cache.directory[key]; exists { if element, exists := cache.directory[key]; exists {
cache.mutex.RUnlock()
keyMutex.RUnlock() keyMutex.RUnlock()
cache.mutex.RUnlock()
cache.mutex.Lock() cache.mutex.Lock()
cache.promoteElement(element) cache.promoteElement(element)
cache.mutex.Unlock() cache.mutex.Unlock()
...@@ -201,11 +201,11 @@ func (cache *LRUCache) Get(key interface{}) (result interface{}) { ...@@ -201,11 +201,11 @@ func (cache *LRUCache) Get(key interface{}) (result interface{}) {
result = element.GetValue().(*lruCacheElement).value result = element.GetValue().(*lruCacheElement).value
keyMutex.RUnlock()
} else { } else {
cache.mutex.RUnlock() cache.mutex.RUnlock()
} }
keyMutex.RUnlock()
cache.krwMutex.Free(key) cache.krwMutex.Free(key)
return return
...@@ -243,9 +243,10 @@ func (cache *LRUCache) Delete(key interface{}) bool { ...@@ -243,9 +243,10 @@ func (cache *LRUCache) Delete(key interface{}) bool {
delete(cache.directory, key) delete(cache.directory, key)
cache.size-- cache.size--
keyMutex.Unlock()
if cache.options.EvictionCallback != nil { if cache.options.EvictionCallback != nil {
cache.options.EvictionCallback(key, entry.GetValue().(*lruCacheElement).key) cache.options.EvictionCallback(key, entry.GetValue().(*lruCacheElement).value)
} }
return true return true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment