summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-cache
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-07-24 10:20:11 +0000
committerLibravatar GitHub <noreply@github.com>2023-07-24 10:20:11 +0000
commitc9f3539b5a9f9746f1629b51a64fb9adf8398cad (patch)
treef2b25a9248f92af5a41f208d0920463a0b307361 /vendor/codeberg.org/gruf/go-cache
parent[chore]: Bump github.com/jackc/pgconn from 1.14.0 to 1.14.1 (#2024) (diff)
downloadgotosocial-c9f3539b5a9f9746f1629b51a64fb9adf8398cad.tar.xz
[chore]: Bump codeberg.org/gruf/go-cache/v3 from 3.4.1 to 3.4.3 (#2022)
Diffstat (limited to 'vendor/codeberg.org/gruf/go-cache')
-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
}