Skip to content

Commit

Permalink
Merge branch 'add-methodsto-sizeconstrainedcache' into include-timebo…
Browse files Browse the repository at this point in the history
…osted-receiptsfield
  • Loading branch information
ganeshvanahalli authored Nov 14, 2024
2 parents 5c7cde2 + 68cb86d commit 01a4427
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 01a4427

Please sign in to comment.