mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
common/helpers: fix race condition when checking last access on expire
This commit is contained in:
3
common/helpers/cache/cache.go
vendored
3
common/helpers/cache/cache.go
vendored
@@ -105,7 +105,8 @@ func (c *Cache[K, V]) DeleteLastAccessedBefore(before time.Time) int {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
for k, v := range c.items {
|
||||
if v.LastAccessed < before.Unix() {
|
||||
last := atomic.LoadInt64(&v.LastAccessed)
|
||||
if last < before.Unix() {
|
||||
delete(c.items, k)
|
||||
count++
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user