Skip to content

Commit

Permalink
Merge pull request hashicorp#58 from MichaelMure/master
Browse files Browse the repository at this point in the history
lru: don't kill the return values of Remove and RemoveOldest
  • Loading branch information
jefferai authored Jul 26, 2019
2 parents 881666a + 60b5852 commit 7f827b3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evicted bool) {
}

// Remove removes the provided key from the cache.
func (c *Cache) Remove(key interface{}) {
func (c *Cache) Remove(key interface{}) (present bool) {
c.lock.Lock()
c.lru.Remove(key)
present = c.lru.Remove(key)
c.lock.Unlock()
return
}

// Resize changes the cache size.
Expand All @@ -101,10 +102,19 @@ func (c *Cache) Resize(size int) (evicted int) {
}

// RemoveOldest removes the oldest item from the cache.
func (c *Cache) RemoveOldest() {
func (c *Cache) RemoveOldest() (key interface{}, value interface{}, ok bool) {
c.lock.Lock()
c.lru.RemoveOldest()
key, value, ok = c.lru.RemoveOldest()
c.lock.Unlock()
return
}

// GetOldest returns the oldest entry
func (c *Cache) GetOldest() (key interface{}, value interface{}, ok bool) {
c.lock.Lock()
key, value, ok = c.lru.GetOldest()
c.lock.Unlock()
return
}

// Keys returns a slice of the keys in the cache, from oldest to newest.
Expand Down

0 comments on commit 7f827b3

Please sign in to comment.