diff --git a/cache.go b/cache.go index d658a42..edea66f 100644 --- a/cache.go +++ b/cache.go @@ -322,16 +322,13 @@ func (c *Cache[K, V]) afterWrite(n, old node.Node[K, V]) { } } -// Delete deletes the association for this key from the cache. +// Invalidate discards any cached value for the key. // -// Returns previous value if any. The deleted result reports whether the key was +// Returns previous value if any. The invalidated result reports whether the key was // present. -func (c *Cache[K, V]) Delete(key K) (value V, deleted bool) { +func (c *Cache[K, V]) Invalidate(key K) (value V, invalidated bool) { var d node.Node[K, V] c.hashmap.Compute(key, func(n node.Node[K, V]) node.Node[K, V] { - if n == nil { - return nil - } d = n return nil }) diff --git a/cache_test.go b/cache_test.go index df35c54..10f145b 100644 --- a/cache_test.go +++ b/cache_test.go @@ -76,7 +76,7 @@ func TestCache_Unbounded(t *testing.T) { c.Set(i, i) } for i := replaced; i < size; i++ { - c.Delete(i) + c.Invalidate(i) } mutex.Lock() @@ -500,7 +500,7 @@ func TestCache_SetWithTTL(t *testing.T) { } } -func TestCache_Delete(t *testing.T) { +func TestCache_Invalidate(t *testing.T) { size := getRandomSize(t) var mutex sync.Mutex m := make(map[DeletionCause]int) @@ -529,7 +529,7 @@ func TestCache_Delete(t *testing.T) { } for i := 0; i < size; i++ { - c.Delete(i) + c.Invalidate(i) } for i := 0; i < size; i++ { @@ -547,7 +547,7 @@ func TestCache_Delete(t *testing.T) { } } -func TestCache_DeleteByFunc(t *testing.T) { +func TestCache_InvalidateByFunc(t *testing.T) { size := getRandomSize(t) var mutex sync.Mutex m := make(map[DeletionCause]int)