mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-04 02:11:49 +09:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user