Skip to content

Commit

Permalink
Make user identifier cache TTL configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Oct 26, 2021
1 parent d5c8760 commit 0cfacfd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions internal/http/services/owncloud/ocs/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Config struct {
CacheWarmupDrivers map[string]map[string]interface{} `mapstructure:"cache_warmup_drivers"`
ResourceInfoCacheSize int `mapstructure:"resource_info_cache_size"`
ResourceInfoCacheTTL int `mapstructure:"resource_info_cache_ttl"`
UserIdentifierCacheTTL int `mapstructure:"user_identifier_cache_ttl"`
}

// Init sets sane defaults
Expand Down Expand Up @@ -66,5 +67,9 @@ func (c *Config) Init() {
c.ResourceInfoCacheSize = 1000000
}

if c.UserIdentifierCacheTTL == 0 {
c.UserIdentifierCacheTTL = 60
}

c.GatewaySvc = sharedconf.GetGatewaySVC(c.GatewaySvc)
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Handler struct {
homeNamespace string
additionalInfoTemplate *template.Template
userIdentifierCache *ttlcache.Cache
userIdentifierCacheTTL time.Duration
resourceInfoCache gcache.Cache
resourceInfoCacheTTL time.Duration
}
Expand Down Expand Up @@ -100,7 +101,7 @@ func (h *Handler) Init(c *config.Config) {
h.additionalInfoTemplate, _ = template.New("additionalInfo").Parse(c.AdditionalInfoAttribute)

h.userIdentifierCache = ttlcache.NewCache()
_ = h.userIdentifierCache.SetTTL(24 * time.Hour)
_ = h.userIdentifierCache.SetTTL(time.Second * time.Duration(c.UserIdentifierCacheTTL))

if h.resourceInfoCacheTTL > 0 {
cwm, err := getCacheWarmupManager(c)
Expand Down

0 comments on commit 0cfacfd

Please sign in to comment.