From 0d3a238d9c45ec18d33ca5a0cededfa81458eb62 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 | 2 ++ pool/cache.go | 11 +++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 496865bb..2532af8e 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 e0628e79..e5f78a03 100644 --- a/go.sum +++ b/go.sum @@ -210,6 +210,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru v0.6.0 h1:uL2shRDx7RTrOrTCUZEGP/wJUFiUI8QT6E7z5o8jga4= github.com/hashicorp/golang-lru v0.6.0/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/golang-lru/v2 v2.0.1 h1:5pv5N1lT1fjLg2VQ5KWc7kmucp2x/kvFOnxuVTqZ6x4= +github.com/hashicorp/golang-lru/v2 v2.0.1/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= diff --git a/pool/cache.go b/pool/cache.go index a50da22f..1a0dec86 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) } }