mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +00:00
util/lru: add Clear method
Updates tailscale/corp#20109 Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: I751a669251a70f0134dd1540c19b274a97608a93
This commit is contained in:
parent
c56e0c4934
commit
47b3476eb7
@ -68,6 +68,12 @@ func (c *Cache[K, V]) Set(key K, value V) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear removes all items from the cache.
|
||||||
|
func (c *Cache[K, V]) Clear() {
|
||||||
|
c.head = nil
|
||||||
|
c.lookup = nil
|
||||||
|
}
|
||||||
|
|
||||||
// Get looks up a key's value from the cache, returning either
|
// Get looks up a key's value from the cache, returning either
|
||||||
// the value or the zero value if it not present.
|
// the value or the zero value if it not present.
|
||||||
//
|
//
|
||||||
|
@ -47,6 +47,10 @@ func TestLRU(t *testing.T) {
|
|||||||
if c.Contains(3) {
|
if c.Contains(3) {
|
||||||
t.Errorf("contains 3; should not")
|
t.Errorf("contains 3; should not")
|
||||||
}
|
}
|
||||||
|
c.Clear()
|
||||||
|
if g, w := c.Len(), 0; g != w {
|
||||||
|
t.Errorf("Len = %d; want %d", g, w)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLRUDeleteCorruption(t *testing.T) {
|
func TestLRUDeleteCorruption(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user