mirror of
https://git.ptzo.gdn/feditools/relay.git
synced 2024-09-21 11:17:12 +00:00
Bump github.com/allegro/bigcache/v3 from 3.0.2 to 3.1.0
Bumps [github.com/allegro/bigcache/v3](https://github.com/allegro/bigcache) from 3.0.2 to 3.1.0. - [Release notes](https://github.com/allegro/bigcache/releases) - [Commits](https://github.com/allegro/bigcache/compare/v3.0.2...v3.1.0) --- updated-dependencies: - dependency-name: github.com/allegro/bigcache/v3 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
parent
5d3ebd7da6
commit
b7d243020a
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/feditools/relay
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/allegro/bigcache/v3 v3.0.2
|
||||
github.com/allegro/bigcache/v3 v3.1.0
|
||||
github.com/contribsys/faktory v1.6.2
|
||||
github.com/contribsys/faktory_worker_go v1.6.0
|
||||
github.com/feditools/go-lib v0.18.2
|
||||
|
4
go.sum
4
go.sum
@ -44,8 +44,8 @@ github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030I
|
||||
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
|
||||
github.com/allegro/bigcache/v3 v3.0.2 h1:AKZCw+5eAaVyNTBmI2fgyPVJhHkdWder3O9IrprcQfI=
|
||||
github.com/allegro/bigcache/v3 v3.0.2/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I=
|
||||
github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk=
|
||||
github.com/allegro/bigcache/v3 v3.1.0/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I=
|
||||
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
|
||||
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
|
||||
|
12
vendor/github.com/allegro/bigcache/v3/README.md
generated
vendored
12
vendor/github.com/allegro/bigcache/v3/README.md
generated
vendored
@ -1,4 +1,4 @@
|
||||
# BigCache [![Build Status](https://github.com/allegro/bigcache/workflows/build/badge.svg)](https://github.com/allegro/bigcache/actions?query=workflow%3Abuild) [![Coverage Status](https://coveralls.io/repos/github/allegro/bigcache/badge.svg?branch=master)](https://coveralls.io/github/allegro/bigcache?branch=master) [![GoDoc](https://godoc.org/github.com/allegro/bigcache?status.svg)](https://godoc.org/github.com/allegro/bigcache) [![Go Report Card](https://goreportcard.com/badge/github.com/allegro/bigcache)](https://goreportcard.com/report/github.com/allegro/bigcache)
|
||||
# BigCache [![Build Status](https://github.com/allegro/bigcache/workflows/build/badge.svg)](https://github.com/allegro/bigcache/actions?query=workflow%3Abuild) [![Coverage Status](https://coveralls.io/repos/github/allegro/bigcache/badge.svg?branch=master)](https://coveralls.io/github/allegro/bigcache?branch=master) [![GoDoc](https://godoc.org/github.com/allegro/bigcache/v3?status.svg)](https://godoc.org/github.com/allegro/bigcache/v3) [![Go Report Card](https://goreportcard.com/badge/github.com/allegro/bigcache/v3)](https://goreportcard.com/report/github.com/allegro/bigcache/v3)
|
||||
|
||||
Fast, concurrent, evicting in-memory cache written to keep big number of entries without impact on performance.
|
||||
BigCache keeps entries on heap but omits GC for them. To achieve that, operations on byte slices take place,
|
||||
@ -11,9 +11,13 @@ Requires Go 1.12 or newer.
|
||||
### Simple initialization
|
||||
|
||||
```go
|
||||
import "github.com/allegro/bigcache/v3"
|
||||
import (
|
||||
"fmt"
|
||||
"context"
|
||||
"github.com/allegro/bigcache/v3"
|
||||
)
|
||||
|
||||
cache, _ := bigcache.NewBigCache(bigcache.DefaultConfig(10 * time.Minute))
|
||||
cache, _ := bigcache.New(context.Background(), bigcache.DefaultConfig(10 * time.Minute))
|
||||
|
||||
cache.Set("my-unique-key", []byte("value"))
|
||||
|
||||
@ -71,7 +75,7 @@ config := bigcache.Config {
|
||||
OnRemoveWithReason: nil,
|
||||
}
|
||||
|
||||
cache, initErr := bigcache.NewBigCache(config)
|
||||
cache, initErr := bigcache.New(context.Background(), config)
|
||||
if initErr != nil {
|
||||
log.Fatal(initErr)
|
||||
}
|
||||
|
32
vendor/github.com/allegro/bigcache/v3/bigcache.go
generated
vendored
32
vendor/github.com/allegro/bigcache/v3/bigcache.go
generated
vendored
@ -1,6 +1,7 @@
|
||||
package bigcache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
@ -40,12 +41,21 @@ const (
|
||||
Deleted = RemoveReason(3)
|
||||
)
|
||||
|
||||
// NewBigCache initialize new instance of BigCache
|
||||
func NewBigCache(config Config) (*BigCache, error) {
|
||||
return newBigCache(config, &systemClock{})
|
||||
// New initialize new instance of BigCache
|
||||
func New(ctx context.Context, config Config) (*BigCache, error) {
|
||||
return newBigCache(ctx, config, &systemClock{})
|
||||
}
|
||||
|
||||
func newBigCache(config Config, clock clock) (*BigCache, error) {
|
||||
// NewBigCache initialize new instance of BigCache
|
||||
//
|
||||
// Deprecated: NewBigCache is deprecated, please use New(ctx, config) instead,
|
||||
// New takes in context and can gracefully
|
||||
// shutdown with context cancellations
|
||||
func NewBigCache(config Config) (*BigCache, error) {
|
||||
return newBigCache(context.Background(), config, &systemClock{})
|
||||
}
|
||||
|
||||
func newBigCache(ctx context.Context, config Config, clock clock) (*BigCache, error) {
|
||||
if !isPowerOfTwo(config.Shards) {
|
||||
return nil, fmt.Errorf("Shards number must be power of two")
|
||||
}
|
||||
@ -94,6 +104,9 @@ func newBigCache(config Config, clock clock) (*BigCache, error) {
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
fmt.Println("ctx done, shutting down bigcache cleanup routine")
|
||||
return
|
||||
case t := <-ticker.C:
|
||||
cache.cleanUp(uint64(t.Unix()))
|
||||
case <-cache.close:
|
||||
@ -163,6 +176,14 @@ func (c *BigCache) Reset() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResetStats resets cache stats
|
||||
func (c *BigCache) ResetStats() error {
|
||||
for _, shard := range c.shards {
|
||||
shard.resetStats()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Len computes number of entries in cache
|
||||
func (c *BigCache) Len() int {
|
||||
var len int
|
||||
@ -209,6 +230,9 @@ func (c *BigCache) Iterator() *EntryInfoIterator {
|
||||
|
||||
func (c *BigCache) onEvict(oldestEntry []byte, currentTimestamp uint64, evict func(reason RemoveReason) error) bool {
|
||||
oldestTimestamp := readTimestampFromEntry(oldestEntry)
|
||||
if currentTimestamp < oldestTimestamp {
|
||||
return false
|
||||
}
|
||||
if currentTimestamp-oldestTimestamp > c.lifeWindow {
|
||||
evict(Expired)
|
||||
return true
|
||||
|
44
vendor/github.com/allegro/bigcache/v3/shard.go
generated
vendored
44
vendor/github.com/allegro/bigcache/v3/shard.go
generated
vendored
@ -30,6 +30,7 @@ type cacheShard struct {
|
||||
|
||||
hashmapStats map[uint64]uint32
|
||||
stats Stats
|
||||
cleanEnabled bool
|
||||
}
|
||||
|
||||
func (s *cacheShard) getWithInfo(key string, hashedKey uint64) (entry []byte, resp Response, err error) {
|
||||
@ -50,12 +51,11 @@ func (s *cacheShard) getWithInfo(key string, hashedKey uint64) (entry []byte, re
|
||||
}
|
||||
|
||||
entry = readEntry(wrappedEntry)
|
||||
oldestTimeStamp := readTimestampFromEntry(wrappedEntry)
|
||||
s.lock.RUnlock()
|
||||
s.hit(hashedKey)
|
||||
if currentTime-oldestTimeStamp >= s.lifeWindow {
|
||||
if s.isExpired(wrappedEntry, currentTime) {
|
||||
resp.EntryStatus = Expired
|
||||
}
|
||||
s.lock.RUnlock()
|
||||
s.hit(hashedKey)
|
||||
return entry, resp, nil
|
||||
}
|
||||
|
||||
@ -130,8 +130,10 @@ func (s *cacheShard) set(key string, hashedKey uint64, entry []byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
if oldestEntry, err := s.entries.Peek(); err == nil {
|
||||
s.onEvict(oldestEntry, currentTimestamp, s.removeOldestEntry)
|
||||
if !s.cleanEnabled {
|
||||
if oldestEntry, err := s.entries.Peek(); err == nil {
|
||||
s.onEvict(oldestEntry, currentTimestamp, s.removeOldestEntry)
|
||||
}
|
||||
}
|
||||
|
||||
w := wrapEntry(currentTimestamp, hashedKey, key, entry, &s.entryBuffer)
|
||||
@ -152,8 +154,10 @@ func (s *cacheShard) set(key string, hashedKey uint64, entry []byte) error {
|
||||
func (s *cacheShard) addNewWithoutLock(key string, hashedKey uint64, entry []byte) error {
|
||||
currentTimestamp := uint64(s.clock.Epoch())
|
||||
|
||||
if oldestEntry, err := s.entries.Peek(); err == nil {
|
||||
s.onEvict(oldestEntry, currentTimestamp, s.removeOldestEntry)
|
||||
if !s.cleanEnabled {
|
||||
if oldestEntry, err := s.entries.Peek(); err == nil {
|
||||
s.onEvict(oldestEntry, currentTimestamp, s.removeOldestEntry)
|
||||
}
|
||||
}
|
||||
|
||||
w := wrapEntry(currentTimestamp, hashedKey, key, entry, &s.entryBuffer)
|
||||
@ -176,8 +180,10 @@ func (s *cacheShard) setWrappedEntryWithoutLock(currentTimestamp uint64, w []byt
|
||||
}
|
||||
}
|
||||
|
||||
if oldestEntry, err := s.entries.Peek(); err == nil {
|
||||
s.onEvict(oldestEntry, currentTimestamp, s.removeOldestEntry)
|
||||
if !s.cleanEnabled {
|
||||
if oldestEntry, err := s.entries.Peek(); err == nil {
|
||||
s.onEvict(oldestEntry, currentTimestamp, s.removeOldestEntry)
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
@ -268,14 +274,21 @@ func (s *cacheShard) del(hashedKey uint64) error {
|
||||
}
|
||||
|
||||
func (s *cacheShard) onEvict(oldestEntry []byte, currentTimestamp uint64, evict func(reason RemoveReason) error) bool {
|
||||
oldestTimestamp := readTimestampFromEntry(oldestEntry)
|
||||
if currentTimestamp-oldestTimestamp > s.lifeWindow {
|
||||
if s.isExpired(oldestEntry, currentTimestamp) {
|
||||
evict(Expired)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *cacheShard) isExpired(oldestEntry []byte, currentTimestamp uint64) bool {
|
||||
oldestTimestamp := readTimestampFromEntry(oldestEntry)
|
||||
if currentTimestamp <= oldestTimestamp { // if currentTimestamp < oldestTimestamp, the result will out of uint64 limits;
|
||||
return false
|
||||
}
|
||||
return currentTimestamp-oldestTimestamp > s.lifeWindow
|
||||
}
|
||||
|
||||
func (s *cacheShard) cleanUp(currentTimestamp uint64) {
|
||||
s.lock.Lock()
|
||||
for {
|
||||
@ -340,6 +353,12 @@ func (s *cacheShard) reset(config Config) {
|
||||
s.lock.Unlock()
|
||||
}
|
||||
|
||||
func (s *cacheShard) resetStats() {
|
||||
s.lock.Lock()
|
||||
s.stats = Stats{}
|
||||
s.lock.Unlock()
|
||||
}
|
||||
|
||||
func (s *cacheShard) len() int {
|
||||
s.lock.RLock()
|
||||
res := len(s.hashmap)
|
||||
@ -430,5 +449,6 @@ func initNewShard(config Config, callback onRemoveCallback, clock clock) *cacheS
|
||||
clock: clock,
|
||||
lifeWindow: uint64(config.LifeWindow.Seconds()),
|
||||
statsEnabled: config.StatsEnabled,
|
||||
cleanEnabled: config.CleanWindow > 0,
|
||||
}
|
||||
}
|
||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -1,4 +1,4 @@
|
||||
# github.com/allegro/bigcache/v3 v3.0.2
|
||||
# github.com/allegro/bigcache/v3 v3.1.0
|
||||
## explicit; go 1.16
|
||||
github.com/allegro/bigcache/v3
|
||||
github.com/allegro/bigcache/v3/queue
|
||||
|
Loading…
Reference in New Issue
Block a user