Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Clear method to SizeConstrainedCache #372

Open
wants to merge 2 commits into
base: wasm-store-compile-target
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
ganeshvanahalli marked this conversation as resolved.
Show resolved Hide resolved
c.size = 0
}
Loading