Skip to content

Commit

Permalink
Merge pull request #372 from OffchainLabs/add-methodsto-sizeconstrain…
Browse files Browse the repository at this point in the history
…edcache

Add Clear method to SizeConstrainedCache
  • Loading branch information
Tristan-Wilson authored Dec 30, 2024
2 parents 26b4dff + 4453ba9 commit 57663a5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions common/lru/blob_lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,21 @@ func (c *SizeConstrainedCache[K, V]) Get(key K) (V, bool) {

return c.lru.Get(key)
}

func (c *SizeConstrainedCache[K, V]) Remove(key K) {
c.lock.Lock()
defer c.lock.Unlock()

if v, ok := c.lru.Peek(key); ok {
c.size -= uint64(len(v))
c.lru.Remove(key)
}
}

func (c *SizeConstrainedCache[K, V]) Clear() {
c.lock.Lock()
defer c.lock.Unlock()

c.lru.Purge()
c.size = 0
}

0 comments on commit 57663a5

Please sign in to comment.