Skip to content

Commit 8b9a55b

Browse files
authored
allow no ttl on local cache by setting ttl to max when config is -1 (#50)
1 parent 09bf5fe commit 8b9a55b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/zcache/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package zcache
33
import (
44
"github.com/allegro/bigcache/v3"
55
"github.com/go-redis/redis/v8"
6+
"math"
67
"time"
78
)
89

@@ -47,7 +48,12 @@ func (c *RemoteConfig) ToRedisConfig() *redis.Options {
4748
}
4849

4950
func (c *LocalConfig) ToBigCacheConfig() bigcache.Config {
50-
return bigcache.DefaultConfig(time.Second * time.Duration(c.EvictionInSeconds))
51+
eviction := time.Duration(c.EvictionInSeconds) * time.Second
52+
if c.EvictionInSeconds < 0 {
53+
eviction = time.Duration(math.MaxInt64)
54+
}
55+
56+
return bigcache.DefaultConfig(eviction)
5157
}
5258

5359
type CombinedConfig struct {

0 commit comments

Comments
 (0)