Skip to content

Commit

Permalink
Add lock/unlock in SetEvictionFunc
Browse files Browse the repository at this point in the history
Signed-off-by: Davanum Srinivas <[email protected]>
  • Loading branch information
dims committed Nov 4, 2024
1 parent 3ea5e8c commit 7a270de
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lru/lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func NewWithEvictionFunc(size int, f EvictionFunc) *Cache {

// SetEvictionFunc updates the eviction func
func (c *Cache) SetEvictionFunc(f EvictionFunc) error {
c.lock.Lock()
defer c.lock.Unlock()
if c.cache.OnEvicted != nil {
return fmt.Errorf("lru cache eviction function is already set")
}
Expand Down

0 comments on commit 7a270de

Please sign in to comment.