Documentation
¶
Overview ¶
Package gocache keeps the Go build cache of the machine's user, which every session's builds share, under a size: the entries used least recently go first, as in Go's own trim, which drops only those unused for five days.
Index ¶
- Constants
- Variables
- func Dir() string
- func Hold(ctx context.Context, dir string, waiting func()) (release func(), err error)
- func ModDir() string
- func Trim(u Usage, target int64, busy func() bool) (freed int64, removed int, err error)
- func TryTrim(dir string) (release func(), ok bool, err error)
- func Use(ctx context.Context, dir string) (release func(), err error)
- type Entry
- type Usage
Constants ¶
const HeldEnv = "BEEKEEPER_GOCACHE_HELD"
HeldEnv names, in a beekeeper run's environment, the cache whose use lock the run holds: a clear started inside the run would wait on its own run.
Variables ¶
var ErrBusy = errors.New("a go build runs")
ErrBusy stops a trim: a Go build began while it ran.
Functions ¶
func Dir ¶
func Dir() string
Dir is the build cache the go command uses: $GOCACHE, else go-build in the user's cache directory; "" when it is off or unknown.
func Hold ¶ added in v0.155.0
Hold takes the cache's use lock exclusive for a clear: it waits until no command holds it (Use) and no trim runs, until ctx ends, and calls waiting once when it has to wait. Runs that start meanwhile wait behind it. release gives both locks back.
func ModDir ¶ added in v0.155.0
func ModDir() string
ModDir is the module cache the go command uses: $GOMODCACHE, else pkg/mod in the first $GOPATH entry, else in go under the home directory; "" when unknown.
func Trim ¶
Trim removes the least recently used entries until the cache holds at most target bytes, and returns the bytes and entries it removed. It asks busy before it starts and every few hundred removals, and stops with ErrBusy once a build runs. An entry gone already is skipped; the go command takes a missing entry for a miss and builds it again.
Types ¶
type Entry ¶
type Entry struct {
Path string
Size int64
// Used is its modification time, which the go command moves on when it
// uses an entry last touched over an hour before.
Used time.Time
}
Entry is one file of the cache: an action or an output.