mirror of
https://github.com/go-gitea/gitea
synced 2025-07-19 16:58:37 +00:00
Refactor cache and disable go-chi cache (#30417)
use built-in cache package to wrap external go-chi cache package
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/queue"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
files_service "code.gitea.io/gitea/services/repository/files"
|
||||
@@ -119,17 +120,15 @@ func getDivergenceCacheKey(repoID int64, branchName string) string {
|
||||
|
||||
// getDivergenceFromCache gets the divergence from cache
|
||||
func getDivergenceFromCache(repoID int64, branchName string) (*git.DivergeObject, bool) {
|
||||
data := cache.GetCache().Get(getDivergenceCacheKey(repoID, branchName))
|
||||
data, ok := cache.GetCache().Get(getDivergenceCacheKey(repoID, branchName))
|
||||
res := git.DivergeObject{
|
||||
Ahead: -1,
|
||||
Behind: -1,
|
||||
}
|
||||
s, ok := data.([]byte)
|
||||
if !ok || len(s) == 0 {
|
||||
if !ok || data == "" {
|
||||
return &res, false
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(s, &res); err != nil {
|
||||
if err := json.Unmarshal(util.UnsafeStringToBytes(data), &res); err != nil {
|
||||
log.Error("json.UnMarshal failed: %v", err)
|
||||
return &res, false
|
||||
}
|
||||
@@ -141,7 +140,7 @@ func putDivergenceFromCache(repoID int64, branchName string, divergence *git.Div
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cache.GetCache().Put(getDivergenceCacheKey(repoID, branchName), bs, 30*24*60*60)
|
||||
return cache.GetCache().Put(getDivergenceCacheKey(repoID, branchName), util.UnsafeBytesToString(bs), 30*24*60*60)
|
||||
}
|
||||
|
||||
func DelDivergenceFromCache(repoID int64, branchName string) error {
|
||||
|
Reference in New Issue
Block a user