Update TwinProduction/gocache to v1.2.3
This commit is contained in:
2
vendor/github.com/TwinProduction/gocache/README.md
generated
vendored
2
vendor/github.com/TwinProduction/gocache/README.md
generated
vendored
@ -5,7 +5,7 @@
|
||||
[](https://codecov.io/gh/TwinProduction/gocache)
|
||||
[](https://github.com/TwinProduction/gocache)
|
||||
[](https://pkg.go.dev/github.com/TwinProduction/gocache)
|
||||
[](https://discord.gg/44p4TRep)
|
||||
[](https://github.com/TwinProduction)
|
||||
|
||||
gocache is an easy-to-use, high-performance, lightweight and thread-safe (goroutine-safe) in-memory key-value cache
|
||||
with support for LRU and FIFO eviction policies as well as expiration, bulk operations and even persistence to file.
|
||||
|
14
vendor/github.com/TwinProduction/gocache/gocache.go
generated
vendored
14
vendor/github.com/TwinProduction/gocache/gocache.go
generated
vendored
@ -239,12 +239,12 @@ func (cache *Cache) SetWithTTL(key string, value interface{}, ttl time.Duration)
|
||||
Key: key,
|
||||
Value: value,
|
||||
RelevantTimestamp: time.Now(),
|
||||
previous: cache.head,
|
||||
next: cache.head,
|
||||
}
|
||||
if cache.head == nil {
|
||||
cache.tail = entry
|
||||
} else {
|
||||
cache.head.next = entry
|
||||
cache.head.previous = entry
|
||||
}
|
||||
cache.head = entry
|
||||
cache.entries[key] = entry
|
||||
@ -519,10 +519,10 @@ func (cache *Cache) moveExistingEntryToHead(entry *Entry) {
|
||||
cache.removeExistingEntryReferences(entry)
|
||||
}
|
||||
if entry != cache.head {
|
||||
entry.previous = cache.head
|
||||
entry.next = nil
|
||||
entry.next = cache.head
|
||||
entry.previous = nil
|
||||
if cache.head != nil {
|
||||
cache.head.next = entry
|
||||
cache.head.previous = entry
|
||||
}
|
||||
cache.head = entry
|
||||
}
|
||||
@ -536,9 +536,9 @@ func (cache *Cache) removeExistingEntryReferences(entry *Entry) {
|
||||
cache.tail = nil
|
||||
cache.head = nil
|
||||
} else if cache.tail == entry {
|
||||
cache.tail = cache.tail.next
|
||||
cache.tail = cache.tail.previous
|
||||
} else if cache.head == entry {
|
||||
cache.head = cache.head.previous
|
||||
cache.head = cache.head.next
|
||||
}
|
||||
if entry.previous != nil {
|
||||
entry.previous.next = entry.next
|
||||
|
19
vendor/github.com/TwinProduction/gocache/janitor.go
generated
vendored
19
vendor/github.com/TwinProduction/gocache/janitor.go
generated
vendored
@ -33,7 +33,7 @@ func (cache *Cache) StartJanitor() error {
|
||||
}
|
||||
cache.stopJanitor = make(chan bool)
|
||||
go func() {
|
||||
// rather than starting from the tail on every run, we can try to start from the last next entry
|
||||
// rather than starting from the tail on every run, we can try to start from the last traversed entry
|
||||
var lastTraversedNode *Entry
|
||||
totalNumberOfExpiredKeysInPreviousRunFromTailToHead := 0
|
||||
backOff := JanitorMinShiftBackOff
|
||||
@ -62,13 +62,14 @@ func (cache *Cache) StartJanitor() error {
|
||||
totalNumberOfExpiredKeysInPreviousRunFromTailToHead = 0
|
||||
}
|
||||
for current != nil {
|
||||
var next *Entry
|
||||
// since we're walking from the tail to the head, we get the previous reference
|
||||
var previous *Entry
|
||||
steps++
|
||||
if current.Expired() {
|
||||
expiredEntriesFound++
|
||||
// Because delete will remove the next reference from the entry, we need to store the
|
||||
// next reference before we delete it
|
||||
next = current.next
|
||||
// Because delete will remove the previous reference from the entry, we need to store the
|
||||
// previous reference before we delete it
|
||||
previous = current.previous
|
||||
cache.delete(current.Key)
|
||||
cache.stats.ExpiredKeys++
|
||||
}
|
||||
@ -76,11 +77,11 @@ func (cache *Cache) StartJanitor() error {
|
||||
lastTraversedNode = nil
|
||||
break
|
||||
}
|
||||
// Travel to the current node's next node only if no specific next node has been specified
|
||||
if next != nil {
|
||||
current = next
|
||||
// Travel to the current node's previous node only if no specific previous node has been specified
|
||||
if previous != nil {
|
||||
current = previous
|
||||
} else {
|
||||
current = current.next
|
||||
current = current.previous
|
||||
}
|
||||
lastTraversedNode = current
|
||||
if steps == JanitorMaxIterationsPerShift || expiredEntriesFound >= JanitorShiftTarget {
|
||||
|
4
vendor/github.com/TwinProduction/gocache/persistence.go
generated
vendored
4
vendor/github.com/TwinProduction/gocache/persistence.go
generated
vendored
@ -120,8 +120,8 @@ func (cache *Cache) ReadFromFile(path string) (int, error) {
|
||||
cache.tail = current
|
||||
cache.head = current
|
||||
} else {
|
||||
previous.next = current
|
||||
current.previous = previous
|
||||
previous.previous = current
|
||||
current.next = previous
|
||||
cache.head = current
|
||||
}
|
||||
previous = entries[i]
|
||||
|
Reference in New Issue
Block a user