Skip to content

Commit b4a8310

Browse files
committed
Ensure memcache TTL cannot be over 30 days
Memcached TTL cannot be > 30 days and if it is attempted the TTL is interpreted as a unix timestamp. This PR ensures that the maximum is set at 30 days. Fix #14571 Signed-off-by: Andrew Thornton <[email protected]>
1 parent c11db35 commit b4a8310

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

modules/setting/cache.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ var (
4949
}
5050
)
5151

52+
const memcachemax = 30 * 24 * time.Hour
53+
5254
func newCacheService() {
5355
sec := Cfg.Section("cache")
5456
if err := sec.MapTo(&CacheService); err != nil {
@@ -58,8 +60,19 @@ func newCacheService() {
5860
CacheService.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"})
5961
switch CacheService.Adapter {
6062
case "memory":
61-
case "redis", "memcache":
63+
case "redis":
64+
CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
65+
case "memcache":
6266
CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
67+
if CacheService.TTL > memcachemax {
68+
log.Warn("Cache service: provided TTL %v is too long for memcache, defaulting to maximum of 30 days", CacheService.TTL)
69+
CacheService.TTL = memcachemax
70+
}
71+
if CacheService.LastCommit.TTL > memcachemax {
72+
log.Warn("Cache service: provided LastCommit cache TTL %v is too long for memcache, defaulting to maximum of 30 days", CacheService.LastCommit.TTL)
73+
74+
CacheService.LastCommit.TTL = memcachemax
75+
}
6376
case "": // disable cache
6477
CacheService.Enabled = false
6578
default:

0 commit comments

Comments
 (0)