Skip to content

Ensure memcache TTL cannot be over 30 days #14592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
15 changes: 14 additions & 1 deletion modules/setting/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ var (
}
)

const memcachemax = 30 * 24 * time.Hour

func newCacheService() {
sec := Cfg.Section("cache")
if err := sec.MapTo(&CacheService); err != nil {
Expand All @@ -58,8 +60,19 @@ func newCacheService() {
CacheService.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"})
switch CacheService.Adapter {
case "memory":
case "redis", "memcache":
case "redis":
CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
case "memcache":
CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
if CacheService.TTL > memcachemax {
log.Warn("Cache service: provided TTL %v is too long for memcache, defaulting to maximum of 30 days", CacheService.TTL)
CacheService.TTL = memcachemax
}
if CacheService.LastCommit.TTL > memcachemax {
log.Warn("Cache service: provided LastCommit cache TTL %v is too long for memcache, defaulting to maximum of 30 days", CacheService.LastCommit.TTL)

CacheService.LastCommit.TTL = memcachemax
}
case "": // disable cache
CacheService.Enabled = false
default:
Expand Down