From 30f7ddb833adfe276a93c1a79e243b8d33bdd41e Mon Sep 17 00:00:00 2001 From: zeripath Date: Tue, 9 Feb 2021 22:29:03 +0000 Subject: Ensure memcache TTL cannot be over 30 days (#14592) Memcached TTL cannot be > 30 days and if it is attempted the TTL is interpreted as a unix timestamp. This PR ensures that the TTL is switched to a unix timestamp in those cases. Fix #14571 Signed-off-by: Andrew Thornton --- modules/git/last_commit_cache.go | 2 +- modules/git/last_commit_cache_gogit.go | 4 ++-- modules/git/last_commit_cache_nogogit.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'modules/git') diff --git a/modules/git/last_commit_cache.go b/modules/git/last_commit_cache.go index 7cca601226..37a59e1fa8 100644 --- a/modules/git/last_commit_cache.go +++ b/modules/git/last_commit_cache.go @@ -25,5 +25,5 @@ func (c *LastCommitCache) getCacheKey(repoPath, ref, entryPath string) string { // Put put the last commit id with commit and entry path func (c *LastCommitCache) Put(ref, entryPath, commitID string) error { log("LastCommitCache save: [%s:%s:%s]", ref, entryPath, commitID) - return c.cache.Put(c.getCacheKey(c.repoPath, ref, entryPath), commitID, c.ttl) + return c.cache.Put(c.getCacheKey(c.repoPath, ref, entryPath), commitID, c.ttl()) } diff --git a/modules/git/last_commit_cache_gogit.go b/modules/git/last_commit_cache_gogit.go index 76c97a4cc0..65d6299bef 100644 --- a/modules/git/last_commit_cache_gogit.go +++ b/modules/git/last_commit_cache_gogit.go @@ -16,14 +16,14 @@ import ( // LastCommitCache represents a cache to store last commit type LastCommitCache struct { repoPath string - ttl int64 + ttl func() int64 repo *Repository commitCache map[string]*object.Commit cache Cache } // NewLastCommitCache creates a new last commit cache for repo -func NewLastCommitCache(repoPath string, gitRepo *Repository, ttl int64, cache Cache) *LastCommitCache { +func NewLastCommitCache(repoPath string, gitRepo *Repository, ttl func() int64, cache Cache) *LastCommitCache { if cache == nil { return nil } diff --git a/modules/git/last_commit_cache_nogogit.go b/modules/git/last_commit_cache_nogogit.go index b9c50b5cfb..0e52d16538 100644 --- a/modules/git/last_commit_cache_nogogit.go +++ b/modules/git/last_commit_cache_nogogit.go @@ -13,14 +13,14 @@ import ( // LastCommitCache represents a cache to store last commit type LastCommitCache struct { repoPath string - ttl int64 + ttl func() int64 repo *Repository commitCache map[string]*Commit cache Cache } // NewLastCommitCache creates a new last commit cache for repo -func NewLastCommitCache(repoPath string, gitRepo *Repository, ttl int64, cache Cache) *LastCommitCache { +func NewLastCommitCache(repoPath string, gitRepo *Repository, ttl func() int64, cache Cache) *LastCommitCache { if cache == nil { return nil } -- cgit v1.2.3