Skip to content

Commit

Permalink
Fix deadlock issue when trying to evict empty cache
Browse files Browse the repository at this point in the history
  • Loading branch information
TwiN committed Jul 1, 2020
1 parent 9eeadb9 commit 2b6f402
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions gocache.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,15 @@ func (cache *Cache) removeExistingEntry(entry *Entry) {

func (cache *Cache) evict() {
cache.mutex.Lock()
if len(cache.entries) == 0 {
if cache.tail == nil || len(cache.entries) == 0 {
cache.mutex.Unlock()
return
}
//var oldestKey string
//oldestKeyTimestamp := time.Now()
//for k, v := range cache.entries {
// if len(oldestKey) == 0 || oldestKeyTimestamp.After(v.RelevantTimestamp) {
// oldestKey = k
// oldestKeyTimestamp = v.RelevantTimestamp
// }
//}
//delete(cache.entries, oldestKey)

if cache.tail != nil {
delete(cache.entries, cache.tail.Key)
cache.tail = cache.tail.next
cache.tail.previous = nil
}

cache.mutex.Unlock()
}

Expand Down

0 comments on commit 2b6f402

Please sign in to comment.