fix: git cache (#38763)

1. always use "last commit cache"
2. correctly build the cache key for any input (SafeCacheKey)
3. fix the git note "last commit cache FIXME" and avoid OOM
This commit is contained in:
wxiaoguang
2026-08-05 00:17:07 +08:00
committed by GitHub
parent 6347a33b34
commit deccd53c24
26 changed files with 213 additions and 298 deletions
+4 -10
View File
@@ -12,7 +12,7 @@ import (
// Cache represents cache settings
type Cache struct {
Adapter string
Interval int
Interval int // GC
Conn string `ini:"-"`
TTL time.Duration `ini:"ITEM_TTL"`
}
@@ -22,8 +22,7 @@ var CacheService = struct {
Cache `ini:"cache"`
LastCommit struct {
TTL time.Duration `ini:"ITEM_TTL"`
CommitsCount int64
TTL time.Duration `ini:"ITEM_TTL"`
} `ini:"cache.last_commit"`
}{
Cache: Cache{
@@ -32,11 +31,9 @@ var CacheService = struct {
TTL: 16 * time.Hour,
},
LastCommit: struct {
TTL time.Duration `ini:"ITEM_TTL"`
CommitsCount int64
TTL time.Duration `ini:"ITEM_TTL"`
}{
TTL: 8760 * time.Hour,
CommitsCount: 1000,
TTL: 8760 * time.Hour,
},
}
@@ -61,9 +58,6 @@ func loadCacheFrom(rootCfg ConfigProvider) {
default:
log.Fatal("Unknown cache adapter: %s", CacheService.Adapter)
}
sec = rootCfg.Section("cache.last_commit")
CacheService.LastCommit.CommitsCount = sec.Key("COMMITS_COUNT").MustInt64(1000)
}
// TTLSeconds returns the TTLSeconds or unix timestamp for memcache