Skip to content

Commit

Permalink
chore: clean up invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
maypok86 committed Sep 18, 2024
1 parent fb69d63 commit ba4902f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
9 changes: 3 additions & 6 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
8 changes: 4 additions & 4 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++ {
Expand All @@ -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)
Expand Down

0 comments on commit ba4902f

Please sign in to comment.