diff --git a/go.mod b/go.mod index 453176e76f..68904ca2a8 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/gorilla/mux v1.8.1 github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 github.com/jellydator/ttlcache/v2 v2.11.1 - github.com/jellydator/ttlcache/v3 v3.1.1 + github.com/jellydator/ttlcache/v3 v3.2.0 github.com/jinzhu/now v1.1.5 github.com/justinas/alice v1.2.0 github.com/leonelquinteros/gotext v1.5.3-0.20230317130943-71a59c05b2c1 diff --git a/go.sum b/go.sum index 785197cc1e..05d79a4890 100644 --- a/go.sum +++ b/go.sum @@ -1544,8 +1544,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jellydator/ttlcache/v2 v2.11.1 h1:AZGME43Eh2Vv3giG6GeqeLeFXxwxn1/qHItqWZl6U64= github.com/jellydator/ttlcache/v2 v2.11.1/go.mod h1:RtE5Snf0/57e+2cLWFYWCCsLas2Hy3c5Z4n14XmSvTI= -github.com/jellydator/ttlcache/v3 v3.1.1 h1:RCgYJqo3jgvhl+fEWvjNW8thxGWsgxi+TPhRir1Y9y8= -github.com/jellydator/ttlcache/v3 v3.1.1/go.mod h1:hi7MGFdMAwZna5n2tuvh63DvFLzVKySzCVW6+0gA2n4= +github.com/jellydator/ttlcache/v3 v3.2.0 h1:6lqVJ8X3ZaUwvzENqPAobDsXNExfUJd61u++uW8a3LE= +github.com/jellydator/ttlcache/v3 v3.2.0/go.mod h1:hi7MGFdMAwZna5n2tuvh63DvFLzVKySzCVW6+0gA2n4= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE= github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74= diff --git a/vendor/github.com/jellydator/ttlcache/v3/cache.go b/vendor/github.com/jellydator/ttlcache/v3/cache.go index a1547fcb28..1ad3afbece 100644 --- a/vendor/github.com/jellydator/ttlcache/v3/cache.go +++ b/vendor/github.com/jellydator/ttlcache/v3/cache.go @@ -148,6 +148,10 @@ func (c *Cache[K, V]) set(key K, value V, ttl time.Duration) *Item[K, V] { c.evict(EvictionReasonCapacityReached, c.items.lru.Back()) } + if ttl == PreviousOrDefaultTTL { + ttl = c.options.ttl + } + // create a new item item := newItem(key, value, ttl, c.options.enableVersionTracking) elem = c.items.lru.PushFront(item) diff --git a/vendor/github.com/jellydator/ttlcache/v3/item.go b/vendor/github.com/jellydator/ttlcache/v3/item.go index 72568e07e5..c3c26cf6ba 100644 --- a/vendor/github.com/jellydator/ttlcache/v3/item.go +++ b/vendor/github.com/jellydator/ttlcache/v3/item.go @@ -9,6 +9,10 @@ const ( // NoTTL indicates that an item should never expire. NoTTL time.Duration = -1 + // PreviousOrDefaultTTL indicates that existing TTL of item should be used + // default TTL will be used as fallback if item doesn't exist + PreviousOrDefaultTTL time.Duration = -2 + // DefaultTTL indicates that the default TTL value of the cache // instance should be used. DefaultTTL time.Duration = 0 @@ -58,17 +62,23 @@ func (item *Item[K, V]) update(value V, ttl time.Duration) { defer item.mu.Unlock() item.value = value + + // update version if enabled + if item.version > -1 { + item.version++ + } + + // no need to update ttl or expiry in this case + if ttl == PreviousOrDefaultTTL { + return + } + item.ttl = ttl // reset expiration timestamp because the new TTL may be // 0 or below item.expiresAt = time.Time{} item.touchUnsafe() - - // update version if enabled - if item.version > -1 { - item.version++ - } } // touch updates the item's expiration timestamp. diff --git a/vendor/modules.txt b/vendor/modules.txt index 9c5837990c..06aa65cd9d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1217,7 +1217,7 @@ github.com/jbenet/go-context/io # github.com/jellydator/ttlcache/v2 v2.11.1 ## explicit; go 1.15 github.com/jellydator/ttlcache/v2 -# github.com/jellydator/ttlcache/v3 v3.1.1 +# github.com/jellydator/ttlcache/v3 v3.2.0 ## explicit; go 1.18 github.com/jellydator/ttlcache/v3 # github.com/jinzhu/now v1.1.5