Help us shape the future of Go! Take the 2026 Go Developer Survey

gocache

package
v0.108.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

This section is empty.

Variables

View Source
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 Trim

func Trim(u Usage, target int64, busy func() bool) (freed int64, removed int, err error)

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.

type Usage

type Usage struct {
	Dir     string
	Entries []Entry
	Bytes   int64
}

Usage is what a scan found: the entries, least recently used first, and their total size.

func Scan

func Scan(dir string) (Usage, error)

Scan reads the cache's entries: the files of its 256 two-hex-digit subdirectories. Everything else (its README, trim.txt, fuzz corpora) is left out, and a missing cache is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL