From d1e4ec464fec17462dfa6ba3b14f8f37bfb8d49e Mon Sep 17 00:00:00 2001 From: Andrii Skomorokhov Date: Wed, 10 Sep 2025 15:39:24 +0200 Subject: [PATCH] Add ResetKeyMetadata method to resets per-key metadata. --- bigcache.go | 8 ++++++++ shard.go | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/bigcache.go b/bigcache.go index b3aa37bb..8328e939 100644 --- a/bigcache.go +++ b/bigcache.go @@ -188,6 +188,14 @@ func (c *BigCache) ResetStats() error { return nil } +// ResetKeyMetadata resets per-key metadata +func (c *BigCache) ResetKeyMetadata() error { + for _, shard := range c.shards { + shard.resetKeyMetadata(c.config) + } + return nil +} + // Len computes the number of entries in the cache. func (c *BigCache) Len() int { var len int diff --git a/shard.go b/shard.go index 4f03b53e..d9c25432 100644 --- a/shard.go +++ b/shard.go @@ -359,6 +359,12 @@ func (s *cacheShard) resetStats() { s.lock.Unlock() } +func (s *cacheShard) resetKeyMetadata(config Config) { + s.lock.Lock() + s.hashmapStats = make(map[uint64]uint32, config.initialShardSize()) + s.lock.Unlock() +} + func (s *cacheShard) len() int { s.lock.RLock() res := len(s.hashmap)