| # This file reports differences detected by import.go since the last import. |
| # This is only for human review and not machine consumption. |
| # Please see go/thirdpartygo for more information. |
| # DO NOT EDIT. This must only be generated by //third_party/golang/import.go. |
| |
| @@ |
| +// Package simplelru contains intefrace and implementation of linked-list based LRU cache. |
| package simplelru |
| |
| import ( |
| @@ func (c *LRU) Peek(key interface{}) (value interface{}, ok bool) { |
| // Remove removes the provided key from the cache, returning if the |
| // key was contained. |
| func (c *LRU) Remove(key interface{}) (present bool) { |
| - if ent, ok := c.items[key]; ok { |
| + ent, present := c.items[key] |
| + if present { |
| c.removeElement(ent) |
| - return true |
| } |
| - return false |
| + return present |
| +} |
| + |
| +// RemoveWithoutEvict removes the provided key from the cache without triggering |
| +// onEvict callback, returning if the key was contained. |
| +func (c *LRU) RemoveWithoutEvict(key interface{}) (present bool) { |
| + ent, present := c.items[key] |
| + if present { |
| + c.removeWithoutEvict(ent) |
| + } |
| + return present |
| } |
| |
| // RemoveOldest removes the oldest item from the cache. |
| @@ func (c *LRU) removeOldest() { |
| |
| // removeElement is used to remove a given list element from the cache |
| func (c *LRU) removeElement(e *list.Element) { |
| - c.evictList.Remove(e) |
| - kv := e.Value.(*entry) |
| - delete(c.items, kv.key) |
| + kv := c.removeWithoutEvict(e) |
| if c.onEvict != nil { |
| c.onEvict(kv.key, kv.value) |
| } |
| } |
| + |
| +// removeWithoutEvict is used to remove a given list element from the cache |
| +// without triggering onEvict callback to be called. |
| +func (c *LRU) removeWithoutEvict(e *list.Element) *entry { |
| + c.evictList.Remove(e) |
| + kv := e.Value.(*entry) |
| + delete(c.items, kv.key) |
| + return kv |
| +} |