Skip to content

Commit

Permalink
Extra safety
Browse files Browse the repository at this point in the history
  • Loading branch information
mgnsk committed Feb 13, 2021
1 parent 74d7252 commit 7079ed1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ func (c *Cache) Evict(key interface{}) (interface{}, bool) {
// don't lock it to prevent deadlock.
return nil, false
}
c.records.Delete(key)
old, ok := c.records.LoadAndDelete(key)
if !ok || old.(*record) != r {
panic("evcache: inconsistent map state")
}
return c.finalize(key, r.(*record))
}

Expand Down Expand Up @@ -354,7 +357,10 @@ func (c *Cache) deleteIfEqualsLocked(key interface{}, r *record) bool {
if old.(*record) != r {
return false
}
c.records.Delete(key)
old, ok = c.records.LoadAndDelete(key)
if !ok || old.(*record) != r {
panic("evcache: inconsistent map state")
}
return true
}

Expand Down

0 comments on commit 7079ed1

Please sign in to comment.