From 45666ac06124722f8e18c25f909390e4dc479768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20-=20=E3=82=A2=E3=83=AC=E3=83=83=E3=82=AF=E3=82=B9?= Date: Mon, 17 Jun 2024 09:34:45 +0200 Subject: [PATCH] Default values for cache expiration (#42) * default LRU * default value for LRU expiration --- client.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index 52b594b..126471b 100644 --- a/client.go +++ b/client.go @@ -31,23 +31,30 @@ func NewClient(logger logger.Logger, service proto.Service, cfg Config) *Client ticker = time.NewTicker(cfg.UpdateFreq.Duration) } - cache := NewRedisCache(redisClient, time.Minute) + redisExpiration := time.Hour + if cfg.Redis.KeyTTL > 0 { + redisExpiration = cfg.Redis.KeyTTL + } + cache := NewRedisCache(redisClient, redisExpiration) + quotaCache := QuotaCache(cache) if cfg.LRUSize > 0 { - quotaCache = NewLRU(quotaCache, cfg.LRUSize, cfg.LRUExpiration.Duration) + lruExpiration := time.Minute + if cfg.LRUExpiration.Duration > 0 { + lruExpiration = cfg.LRUExpiration.Duration + } + quotaCache = NewLRU(quotaCache, cfg.LRUSize, lruExpiration) } - permCache := PermissionCache(cache) - return &Client{ cfg: cfg, service: service, usage: &usageTracker{ Usage: make(map[time.Time]usageRecord), }, - usageCache: UsageCache(cache), + usageCache: cache, quotaCache: quotaCache, - permCache: permCache, + permCache: cache, quotaClient: proto.NewQuotaControlClient(cfg.URL, &authorizedClient{ client: http.DefaultClient, bearerToken: cfg.AuthToken,