allegro / allegro/bigcache

Disable eviction

Abierto
#150 8 comentarios 0 reacciones 0 asignados Ver en GitHub
future
Lenguaje dominante
Go
Estrellas
8.2k
Forks
614
Merge medio
5 d 12 h
PR fusionados (30 d)
1

Descripción

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
}
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.