From 0cbc0c2f2185b5931b921fc673939a8fe73e14e0 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 30 Dec 2022 13:44:07 +0300 Subject: [PATCH] [#5] pool: Update `hashicorp/lru` to v2 Signed-off-by: Evgenii Stratonikov --- go.mod | 3 ++- go.sum | Bin 73336 -> 73523 bytes pool/cache.go | 11 +++++------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 496865b..2532af8 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/TrueCloudLab/tzhash v1.7.0 github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12 github.com/google/uuid v1.3.0 - github.com/hashicorp/golang-lru v0.6.0 + github.com/hashicorp/golang-lru/v2 v2.0.1 github.com/mr-tron/base58 v1.2.0 github.com/nspcc-dev/neo-go v0.100.1 github.com/stretchr/testify v1.8.1 @@ -24,6 +24,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/gorilla/websocket v1.4.2 // indirect + github.com/hashicorp/golang-lru v0.6.0 // indirect github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 // indirect github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20221202075445-cb5c18dc73eb // indirect github.com/nspcc-dev/rfc6979 v0.2.0 // indirect diff --git a/go.sum b/go.sum index e0628e7977c5220f1f1c83527e8c04cd1f10e73e..e5f78a03a6402fa804cec2aa114d539dde1699d0 100644 GIT binary patch delta 127 zcmeydhh_6VmJL;blVt*hE%eKb6v~YB4D<{YG7POu3(8FW40A#Z)3SWhjlu#=y~C5u zvvW(63ydoCv&-E4^D0WiLJFhIDkk#=Dow6$5Y-M$bxX0#FUZSvGz$#%N;WNX49fQo f4bFGVs7&)U(vM0l$ai!%3vw?=_1&Bk$a59|$E_=A delta 14 WcmdnIkLAZ6mJL;bn@xlModEzip9ie~ diff --git a/pool/cache.go b/pool/cache.go index b051e5f..c5f36ab 100644 --- a/pool/cache.go +++ b/pool/cache.go @@ -5,11 +5,11 @@ import ( "sync/atomic" "github.com/TrueCloudLab/frostfs-sdk-go/session" - lru "github.com/hashicorp/golang-lru" + lru "github.com/hashicorp/golang-lru/v2" ) type sessionCache struct { - cache *lru.Cache + cache *lru.Cache[string, *cacheValue] currentEpoch uint64 } @@ -18,7 +18,7 @@ type cacheValue struct { } func newCache() (*sessionCache, error) { - cache, err := lru.New(100) + cache, err := lru.New[string, *cacheValue](100) if err != nil { return nil, err } @@ -30,12 +30,11 @@ func newCache() (*sessionCache, error) { // and context related fields. Returns nil if token is missing in the cache. // It is safe to modify and re-sign returned session token. func (c *sessionCache) Get(key string) (session.Object, bool) { - valueRaw, ok := c.cache.Get(key) + value, ok := c.cache.Get(key) if !ok { return session.Object{}, false } - value := valueRaw.(*cacheValue) if c.expired(value) { c.cache.Remove(key) return session.Object{}, false @@ -52,7 +51,7 @@ func (c *sessionCache) Put(key string, token session.Object) bool { func (c *sessionCache) DeleteByPrefix(prefix string) { for _, key := range c.cache.Keys() { - if strings.HasPrefix(key.(string), prefix) { + if strings.HasPrefix(key, prefix) { c.cache.Remove(key) } } -- 2.45.2