diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-04-13 16:38:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-13 08:38:44 +0000 |
commit | c248f010ad08a7017ba1d418e9b6a5b72aff0c88 (patch) | |
tree | 4e479229bc1248e123f2ed9296edf80fe96cdd65 /modules/git | |
parent | 8fd8978b4934865c2b041216e84e923ad574a4c7 (diff) | |
download | gitea-c248f010ad08a7017ba1d418e9b6a5b72aff0c88.tar.gz gitea-c248f010ad08a7017ba1d418e9b6a5b72aff0c88.zip |
Refactor cache and disable go-chi cache (#30417)
use built-in cache package to wrap external go-chi cache package
Diffstat (limited to 'modules/git')
-rw-r--r-- | modules/git/last_commit_cache.go | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/modules/git/last_commit_cache.go b/modules/git/last_commit_cache.go index 5b62b90b27..cf9c10d7b4 100644 --- a/modules/git/last_commit_cache.go +++ b/modules/git/last_commit_cache.go @@ -7,18 +7,11 @@ import ( "crypto/sha256" "fmt" + "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" ) -// Cache represents a caching interface -type Cache interface { - // Put puts value into cache with key and expire time. - Put(key string, val any, timeout int64) error - // Get gets cached value by given key. - Get(key string) any -} - func getCacheKey(repoPath, commitID, entryPath string) string { hashBytes := sha256.Sum256([]byte(fmt.Sprintf("%s:%s:%s", repoPath, commitID, entryPath))) return fmt.Sprintf("last_commit:%x", hashBytes) @@ -30,11 +23,11 @@ type LastCommitCache struct { ttl func() int64 repo *Repository commitCache map[string]*Commit - cache Cache + cache cache.StringCache } // NewLastCommitCache creates a new last commit cache for repo -func NewLastCommitCache(count int64, repoPath string, gitRepo *Repository, cache Cache) *LastCommitCache { +func NewLastCommitCache(count int64, repoPath string, gitRepo *Repository, cache cache.StringCache) *LastCommitCache { if cache == nil { return nil } @@ -65,7 +58,7 @@ func (c *LastCommitCache) Get(ref, entryPath string) (*Commit, error) { return nil, nil } - commitID, ok := c.cache.Get(getCacheKey(c.repoPath, ref, entryPath)).(string) + commitID, ok := c.cache.Get(getCacheKey(c.repoPath, ref, entryPath)) if !ok || commitID == "" { return nil, nil } |