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

gocache

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gocache trims the Go build cache to the working set of one CI run, so the cache CI saves stays the size of what a build actually uses instead of accreting a layer of stale compile output with every save.

It relies on how cmd/go maintains the cache (src/cmd/go/internal/cache/cache.go): every use of an entry refreshes its mtime, but at most once per mtimeInterval (one hour). So after a run, every entry that run read or wrote has an mtime no earlier than an hour before the run started; anything older went unused. Go's own trim deletes entries unused for five days, which never fires in a cache CI restores and re-saves daily.

Trim removes exactly what Go's own trim would remove — files and executable-entry directories named *-a or *-d inside the 256 two-hex-digit subdirectories — only with a much shorter cutoff. README, trim.txt, testexpire.txt and fuzz/ are never touched.

The idea comes from cloudx-io/setup-go's trim-gocache post step; it is reimplemented here so the template takes no third-party action and needs no post hook (CI saves the cache in an explicit step, so the trim simply runs before it).

Index

Constants

View Source
const MtimeInterval = time.Hour

MtimeInterval is cmd/go's mtimeInterval: an entry's mtime is refreshed on use only if it is at least this old. A cutoff must leave at least this much slack before the run's start.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stats

type Stats struct {
	Kept, Removed           int
	KeptBytes, RemovedBytes int64
}

Stats reports what a trim kept and removed.

func Trim

func Trim(dir string, cutoff time.Time) (Stats, error)

Trim deletes cache entries in dir whose mtime is before cutoff. Errors on individual entries are ignored, as cmd/go's own trim ignores them: a file that cannot be removed only means a slightly larger cache.

func (Stats) String

func (s Stats) String() string

Jump to

Keyboard shortcuts

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