allegro / allegro/bigcache

Disable eviction

Offen
#150 8 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
future
Vorherrschende Sprache
Go
Sterne
8.2k
Forks
614
Ø Merge
5 T. 12 Std.
Gemergte PRs (30 T.)
1

Beschreibung

Something like
```diff
diff --git a/bigcache.go b/bigcache.go
index b387926..32db182 100644
--- a/bigcache.go
+++ b/bigcache.go
@@ -171,7 +171,7 @@ 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 > c.lifeWindow {
+ if (int(c.lifeWindow) >= 0) && (currentTimestamp-oldestTimestamp > c.lifeWindow) {
evict(Expired)
return true
}
diff --git a/config.go b/config.go
index 918908c..c5905f4 100644
--- a/config.go
+++ b/config.go
@@ -7,6 +7,7 @@ type Config struct {
// Number of cache shards, value must be a power of two
Shards int
// Time after which entry can be evicted
+ // No eviction if LifeWindow < 0
LifeWindow time.Duration
// Interval between removing expired entries (clean up).
// If set to < 0 then no action is performed. Setting to < 1 second is counterproductive — bigcache has a one second resolution.
diff --git a/shard.go b/shard.go
index a31094f..6e5612a 100644
--- a/shard.go
+++ b/shard.go
@@ -134,7 +134,7 @@ func (s *cacheShard) del(key string, 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 (int(s.lifeWindow) >= 0) && (currentTimestamp-oldestTimestamp > s.lifeWindow) {
evict(Expired)
return true
}
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.