[#5] pool: Update `hashicorp/lru` to v2

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
pull/18/merge
Evgenii Stratonikov 2022-12-30 13:44:07 +03:00 committed by fyrchik
parent cf64ddfb14
commit 0d3a238d9c
3 changed files with 9 additions and 7 deletions

3
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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)
}
}