Skip to content

Commit 57663a5

Browse files
Merge pull request #372 from OffchainLabs/add-methodsto-sizeconstrainedcache
Add Clear method to SizeConstrainedCache
2 parents 26b4dff + 4453ba9 commit 57663a5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

common/lru/blob_lru.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,21 @@ func (c *SizeConstrainedCache[K, V]) Get(key K) (V, bool) {
8282

8383
return c.lru.Get(key)
8484
}
85+
86+
func (c *SizeConstrainedCache[K, V]) Remove(key K) {
87+
c.lock.Lock()
88+
defer c.lock.Unlock()
89+
90+
if v, ok := c.lru.Peek(key); ok {
91+
c.size -= uint64(len(v))
92+
c.lru.Remove(key)
93+
}
94+
}
95+
96+
func (c *SizeConstrainedCache[K, V]) Clear() {
97+
c.lock.Lock()
98+
defer c.lock.Unlock()
99+
100+
c.lru.Purge()
101+
c.size = 0
102+
}

0 commit comments

Comments
 (0)