Skip to content

Commit

Permalink
deletes the old key from items map only if the old key is not nil (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: prpeh <[email protected]>
  • Loading branch information
hadv and prpeh authored Jun 10, 2024
1 parent b011339 commit 32dd86a
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions ringcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,10 @@ func (c *RingCache) Add(key, value interface{}) (evicted bool) {
c.onEvict(k, c.items[k])
evicted = true
}
delete(c.items, k)
}

size := c.Len()
c.items[key] = value
if size < c.Len() {
delete(c.items, k)
}
c.keys[c.next] = key
c.next = (c.next + 1) % c.maxSize
return
Expand Down

0 comments on commit 32dd86a

Please sign in to comment.