summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-cache/v3/result/cache.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/codeberg.org/gruf/go-cache/v3/result/cache.go')
-rw-r--r--vendor/codeberg.org/gruf/go-cache/v3/result/cache.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/vendor/codeberg.org/gruf/go-cache/v3/result/cache.go b/vendor/codeberg.org/gruf/go-cache/v3/result/cache.go
index 74644b073..a86a72c77 100644
--- a/vendor/codeberg.org/gruf/go-cache/v3/result/cache.go
+++ b/vendor/codeberg.org/gruf/go-cache/v3/result/cache.go
@@ -228,11 +228,15 @@ func (c *Cache[Value]) Load(lookup string, load func() (Value, error), keyParts
var evict func()
- // Acquire cache lock.
+ // Lock cache.
c.cache.Lock()
+
defer func() {
+ // Unlock cache.
c.cache.Unlock()
+
if evict != nil {
+ // Call evict.
evict()
}
}()
@@ -266,21 +270,25 @@ func (c *Cache[Value]) Store(value Value, store func() error) error {
var evict func()
- // Acquire cache lock.
+ // Lock cache.
c.cache.Lock()
+
defer func() {
+ // Unlock cache.
c.cache.Unlock()
+
if evict != nil {
+ // Call evict.
evict()
}
+
+ // Call invalidate.
+ c.invalid(value)
}()
// Store result in cache.
evict = c.store(result)
- // Call invalidate.
- c.invalid(value)
-
return nil
}