commit 8f2d3ca664a060918c6bf849cbb30ddb2b854433
parent 96f11e757cd28ad3e6ce6ad243ee8bd459d3b124
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 14 Nov 2022 09:14:34 +0000
[chore]: Bump codeberg.org/gruf/go-cache/v3 from 3.1.7 to 3.1.8 (#1043)
Bumps codeberg.org/gruf/go-cache/v3 from 3.1.7 to 3.1.8.
---
updated-dependencies:
- dependency-name: codeberg.org/gruf/go-cache/v3
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat:
6 files changed, 33 insertions(+), 47 deletions(-)
diff --git a/go.mod b/go.mod
@@ -6,7 +6,7 @@ require (
codeberg.org/gruf/go-bytesize v1.0.0
codeberg.org/gruf/go-byteutil v1.0.2
codeberg.org/gruf/go-cache/v2 v2.1.4
- codeberg.org/gruf/go-cache/v3 v3.1.7
+ codeberg.org/gruf/go-cache/v3 v3.1.8
codeberg.org/gruf/go-debug v1.2.0
codeberg.org/gruf/go-errors/v2 v2.0.2
codeberg.org/gruf/go-kv v1.5.2
diff --git a/go.sum b/go.sum
@@ -71,8 +71,8 @@ codeberg.org/gruf/go-byteutil v1.0.2 h1:OesVyK5VKWeWdeDR00zRJ+Oy8hjXx1pBhn7WVvcZ
codeberg.org/gruf/go-byteutil v1.0.2/go.mod h1:cWM3tgMCroSzqoBXUXMhvxTxYJp+TbCr6ioISRY5vSU=
codeberg.org/gruf/go-cache/v2 v2.1.4 h1:r+6wJiTHZn0qqf+p1VtAjGOgXXJl7s8txhPIwoSMZtI=
codeberg.org/gruf/go-cache/v2 v2.1.4/go.mod h1:j7teiz814lG0PfSfnUs+6HA+2/jcjTAR71Ou3Wbt2Xk=
-codeberg.org/gruf/go-cache/v3 v3.1.7 h1:mWeLxh4CnIfBIbzxdCPlPsRjrernqIlFsMQdLQhUBMo=
-codeberg.org/gruf/go-cache/v3 v3.1.7/go.mod h1:h6im2UVGdrGtNt4IVKARVeoW4kAdok5ts7CbH15UWXs=
+codeberg.org/gruf/go-cache/v3 v3.1.8 h1:wbUef/QtRstEb7sSpQYHT5CtSFtKkeZr4ZhOTXqOpac=
+codeberg.org/gruf/go-cache/v3 v3.1.8/go.mod h1:h6im2UVGdrGtNt4IVKARVeoW4kAdok5ts7CbH15UWXs=
codeberg.org/gruf/go-debug v1.2.0 h1:WBbTMnK1ArFKUmgv04aO2JiC/daTOB8zQGi521qb7OU=
codeberg.org/gruf/go-debug v1.2.0/go.mod h1:N+vSy9uJBQgpQcJUqjctvqFz7tBHJf+S/PIjLILzpLg=
codeberg.org/gruf/go-errors/v2 v2.0.0/go.mod h1:ZRhbdhvgoUA3Yw6e56kd9Ox984RrvbEFC2pOXyHDJP4=
diff --git a/vendor/codeberg.org/gruf/go-cache/v3/result/cache.go b/vendor/codeberg.org/gruf/go-cache/v3/result/cache.go
@@ -178,10 +178,8 @@ func (c *Cache[Value]) Load(lookup string, load func() (Value, error), keyParts
c.cache.Lock()
defer c.cache.Unlock()
- // Attempt to cache this result.
- if key, ok := c.storeResult(res); !ok {
- return zero, ConflictError{key}
- }
+ // Cache this result
+ c.storeResult(res)
}
// Catch and return error
@@ -211,11 +209,8 @@ func (c *Cache[Value]) Store(value Value, store func() error) error {
c.cache.Lock()
defer c.cache.Unlock()
- // Attempt to cache result, only return conflict
- // error if the appropriate flag has been set.
- if key, ok := c.storeResult(result); !ok {
- return ConflictError{key}
- }
+ // Cache this result
+ c.storeResult(result)
return nil
}
@@ -285,7 +280,7 @@ func (c *Cache[Value]) Cap() int {
return c.cache.Cache.Cap()
}
-func (c *Cache[Value]) storeResult(res result[Value]) (string, bool) {
+func (c *Cache[Value]) storeResult(res result[Value]) {
for _, key := range res.Keys {
pkeys := key.key.pkeys
@@ -293,16 +288,18 @@ func (c *Cache[Value]) storeResult(res result[Value]) (string, bool) {
pkey, ok := pkeys[key.value]
if ok {
- // Look for overlap with non error keys,
- // as an overlap for some but not all keys
- // could produce inconsistent results.
+ // Get the overlapping result with this key.
entry, _ := c.cache.Cache.Get(pkey)
- if entry.Value.Error == nil {
- return key.value, false
- }
- // Delete existing error result
- c.cache.Cache.Delete(pkey)
+ // From conflicting entry, drop this key, this
+ // will prevent eviction cleanup key confusion.
+ entry.Value.Keys.drop(key.key.name)
+
+ if len(entry.Value.Keys) == 0 {
+ // We just over-wrote the only lookup key for
+ // this value, so we drop its primary key too
+ c.cache.Cache.Delete(pkey)
+ }
}
}
@@ -324,13 +321,11 @@ func (c *Cache[Value]) storeResult(res result[Value]) (string, bool) {
}, func(_ int64, item *ttl.Entry[int64, result[Value]]) {
c.cache.Evict(item)
})
-
- return "", true
}
type result[Value any] struct {
// keys accessible under
- Keys []cachedKey
+ Keys cacheKeys
// cached value
Value Value
diff --git a/vendor/codeberg.org/gruf/go-cache/v3/result/error.go b/vendor/codeberg.org/gruf/go-cache/v3/result/error.go
@@ -1,22 +0,0 @@
-package result
-
-import "errors"
-
-// ErrUnkownLookup ...
-var ErrUnknownLookup = errors.New("unknown lookup identifier")
-
-// IsConflictErr returns whether error is due to key conflict.
-func IsConflictErr(err error) bool {
- _, ok := err.(ConflictError)
- return ok
-}
-
-// ConflictError is returned on cache key conflict.
-type ConflictError struct {
- Key string
-}
-
-// Error returns the message for this key conflict error.
-func (c ConflictError) Error() string {
- return "cache conflict for key \"" + c.Key + "\""
-}
diff --git a/vendor/codeberg.org/gruf/go-cache/v3/result/key.go b/vendor/codeberg.org/gruf/go-cache/v3/result/key.go
@@ -77,6 +77,19 @@ func (sk structKeys) generate(a any) []cachedKey {
return keys
}
+type cacheKeys []cachedKey
+
+// drop will drop the cachedKey with lookup name from receiving cacheKeys slice.
+func (ck *cacheKeys) drop(name string) {
+ _ = *ck // move out of loop
+ for i := range *ck {
+ if (*ck)[i].key.name == name {
+ (*ck) = append((*ck)[:i], (*ck)[i+1:]...)
+ break
+ }
+ }
+}
+
// cachedKey represents an actual cached key.
type cachedKey struct {
// key is a reference to the structKey this
diff --git a/vendor/modules.txt b/vendor/modules.txt
@@ -16,7 +16,7 @@ codeberg.org/gruf/go-byteutil
# codeberg.org/gruf/go-cache/v2 v2.1.4
## explicit; go 1.19
codeberg.org/gruf/go-cache/v2
-# codeberg.org/gruf/go-cache/v3 v3.1.7
+# codeberg.org/gruf/go-cache/v3 v3.1.8
## explicit; go 1.19
codeberg.org/gruf/go-cache/v3/result
codeberg.org/gruf/go-cache/v3/ttl