[#5] pool: Update hashicorp/lru
to v2
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
cf64ddfb14
commit
0d3a238d9c
3 changed files with 7 additions and 7 deletions
3
go.mod
3
go.mod
|
@ -9,7 +9,7 @@ require (
|
||||||
github.com/TrueCloudLab/tzhash v1.7.0
|
github.com/TrueCloudLab/tzhash v1.7.0
|
||||||
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12
|
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12
|
||||||
github.com/google/uuid v1.3.0
|
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/mr-tron/base58 v1.2.0
|
||||||
github.com/nspcc-dev/neo-go v0.100.1
|
github.com/nspcc-dev/neo-go v0.100.1
|
||||||
github.com/stretchr/testify v1.8.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/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
|
||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
github.com/gorilla/websocket v1.4.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/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/neo-go/pkg/interop v0.0.0-20221202075445-cb5c18dc73eb // indirect
|
||||||
github.com/nspcc-dev/rfc6979 v0.2.0 // indirect
|
github.com/nspcc-dev/rfc6979 v0.2.0 // indirect
|
||||||
|
|
BIN
go.sum
BIN
go.sum
Binary file not shown.
|
@ -5,11 +5,11 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/TrueCloudLab/frostfs-sdk-go/session"
|
"github.com/TrueCloudLab/frostfs-sdk-go/session"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type sessionCache struct {
|
type sessionCache struct {
|
||||||
cache *lru.Cache
|
cache *lru.Cache[string, *cacheValue]
|
||||||
currentEpoch uint64
|
currentEpoch uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ type cacheValue struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCache() (*sessionCache, error) {
|
func newCache() (*sessionCache, error) {
|
||||||
cache, err := lru.New(100)
|
cache, err := lru.New[string, *cacheValue](100)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,11 @@ func newCache() (*sessionCache, error) {
|
||||||
// and context related fields. Returns nil if token is missing in the cache.
|
// and context related fields. Returns nil if token is missing in the cache.
|
||||||
// It is safe to modify and re-sign returned session token.
|
// It is safe to modify and re-sign returned session token.
|
||||||
func (c *sessionCache) Get(key string) (session.Object, bool) {
|
func (c *sessionCache) Get(key string) (session.Object, bool) {
|
||||||
valueRaw, ok := c.cache.Get(key)
|
value, ok := c.cache.Get(key)
|
||||||
if !ok {
|
if !ok {
|
||||||
return session.Object{}, false
|
return session.Object{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
value := valueRaw.(*cacheValue)
|
|
||||||
if c.expired(value) {
|
if c.expired(value) {
|
||||||
c.cache.Remove(key)
|
c.cache.Remove(key)
|
||||||
return session.Object{}, false
|
return session.Object{}, false
|
||||||
|
@ -52,7 +51,7 @@ func (c *sessionCache) Put(key string, token session.Object) bool {
|
||||||
|
|
||||||
func (c *sessionCache) DeleteByPrefix(prefix string) {
|
func (c *sessionCache) DeleteByPrefix(prefix string) {
|
||||||
for _, key := range c.cache.Keys() {
|
for _, key := range c.cache.Keys() {
|
||||||
if strings.HasPrefix(key.(string), prefix) {
|
if strings.HasPrefix(key, prefix) {
|
||||||
c.cache.Remove(key)
|
c.cache.Remove(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue