mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-04 22:37:55 +00:00
Cache entries were only scoped by repository, so an entry a pull request saved could be restored on the default branch, for example through a `restore-keys` prefix. Entries now carry the ref of the job that saved them. As on GitHub ([Restrictions for accessing a cache](https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching#restrictions-for-accessing-a-cache)), a job restores entries of its own ref first, then of its pull request's base branch, then of the default branch. Pull request events are scoped by their pull request number. Entries saved before this change are no longer restored and expire through `cache.retention`, so caches start cold once after the upgrade. Runners sharing a cache, and an external `cache-server`, should be upgraded together. Co-authored-by: silverwind <[email protected]> Co-authored-by: silverwind <[email protected]> Reviewed-on: https://gitea.com/gitea/runner/pulls/1361 Reviewed-by: silverwind <[email protected]> Co-authored-by: JorgeDLMV <[email protected]>
32 lines
980 B
Go
32 lines
980 B
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// Copyright 2023 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package artifactcache
|
|
|
|
import "time"
|
|
|
|
type Request struct {
|
|
Key string `json:"key" `
|
|
Version string `json:"version"`
|
|
Size int64 `json:"cacheSize"`
|
|
}
|
|
|
|
type Cache struct {
|
|
ID uint64 `json:"id"`
|
|
Repo string `json:"repo"`
|
|
Ref string `json:"ref,omitzero"`
|
|
Key string `json:"key"`
|
|
Version string `json:"version"`
|
|
Size int64 `json:"cacheSize"`
|
|
Owner string `json:"owner"` // hashed bearer, so a job's own retry is not another job's reservation
|
|
Complete bool `json:"complete"`
|
|
UsedAt int64 `json:"usedAt"`
|
|
CreatedAt int64 `json:"createdAt"`
|
|
CreatedAtNanos int `json:"createdAtNanos,omitzero"`
|
|
}
|
|
|
|
func (cache *Cache) createdAtNano() int64 {
|
|
return cache.CreatedAt*int64(time.Second) + int64(cache.CreatedAtNanos)
|
|
}
|