Skip to content

Commit

Permalink
Default values for cache expiration (#42)
Browse files Browse the repository at this point in the history
* default LRU

* default value for LRU expiration
  • Loading branch information
klaidliadon authored Jun 17, 2024
1 parent ed094bf commit 45666ac
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 45666ac

Please sign in to comment.