refactor: move go-chi/cache into Gitea (#39530)

The `gitea.com/go-chi/cache` package only exists for Gitea, so it moves
into `modules/cache`.

- `ITEM_TTL = -1` disables caching as documented
- Sub-second TTLs round up instead of never expiring
- The Redis adapter no longer grows a `MacaronCache` hash
- Use two-queue cache for in-memory cache

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind
2026-10-02 18:16:34 +02:00
committed by GitHub
parent 873efed5a6
commit bea6fcaa84
14 changed files with 342 additions and 381 deletions
+8 -2
View File
@@ -25,14 +25,20 @@ type LastCommitCache struct {
// Put puts the last commit id with commit and entry path
func (c *LastCommitCache) Put(ref, entryPath, commitID string) error {
if c.ttlFn() < 0 {
return nil
}
log.Debug("LastCommitCache save: [%s:%s:%s]", ref, entryPath, commitID)
return c.cache.Put(getCacheKey(c.repo, ref, entryPath), commitID, c.ttlFn())
}
// Get gets the last commit information by commit id and entry path
func (c *LastCommitCache) Get(ctx context.Context, ref, entryPath string) (*Commit, error) {
lastCommitID, ok := c.cache.Get(getCacheKey(c.repo, ref, entryPath))
if !ok || lastCommitID == "" {
var lastCommitID string
if c.ttlFn() >= 0 {
lastCommitID, _ = c.cache.Get(getCacheKey(c.repo, ref, entryPath))
}
if lastCommitID == "" {
return nil, nil //nolint:nilnil // return nil when cache miss
}