Skip to content

Commit

Permalink
add lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Welkin committed Dec 26, 2023
1 parent 3bcd944 commit 8cb6909
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions op-node/sources/caching/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,23 @@ func (c *LRUCache) Get(key any) (value any, ok bool) {
return value, ok
}

func (c *LRUCache) Add(key, value any) (evicted bool) {
evicted = c.inner.Add(key, value)
if c.m != nil {
c.m.CacheAdd(c.label, c.inner.Len(), evicted)
}
return evicted
}

func (c *LRUCache) Peek(key any) (value any, ok bool) {
defer c.lock.Unlock()
c.lock.Lock()
return c.inner.Peek(key)
}

func (c *LRUCache) PeekAndCleanOld(key any) (value any, ok bool) {
defer c.lock.Unlock()
c.lock.Lock()
value, ok = c.inner.Peek(key)
if c.m != nil {
c.m.CacheGet(c.label, ok)
Expand All @@ -50,14 +62,6 @@ func (c *LRUCache) PeekAndCleanOld(key any) (value any, ok bool) {
return value, ok
}

func (c *LRUCache) Add(key, value any) (evicted bool) {
evicted = c.inner.Add(key, value)
if c.m != nil {
c.m.CacheAdd(c.label, c.inner.Len(), evicted)
}
return evicted
}

func (c *LRUCache) AddIfNotFull(key, value any) (evicted bool, full bool) {
defer c.lock.Unlock()
c.lock.Lock()
Expand Down

0 comments on commit 8cb6909

Please sign in to comment.