Cache Go in GitHub Actions
Enable a Cache Volume on your runner profile, then configure the action after checkout and Go installation:namespace-profile-my-profile with your profile’s label. cache: false disables setup-go’s GitHub-hosted cache; cache: go mounts Go’s build cache (GOCACHE) and module download cache (GOMODCACHE) on the Cache Volume.
Advanced: gocacheprog-based incremental caching
gocacheprog is an early-access alternative to Go’s built-in build-cache handling. It builds on Cache Volumes, adding a shared remote cache behind the local files on the volume. Builds read local outputs first, fetch missing outputs from the remote cache, and share new outputs across machines.
Install gocacheprog
gocacheprog implements Go’s external build-cache protocol. It requires Go 1.24 or later and supports Linux and macOS on amd64 and arm64. It does not install Go or move compilation to another machine.
Install the latest released binary:
Authentication
No additional authentication setup is required for jobs running on Namespace.gocacheprog automatically uses the credentials already provided to the job.
Enable remote caching
Tell Go to launch the helper for builds and tests:main. Set -tag to choose another instance. No separate provisioning command or client certificate setup is required.
Instance provisioning retries for up to five minutes. After provisioning, the helper waits up to five seconds for the cache endpoint to respond. Provisioning failures are reported to Go; an endpoint that remains unavailable produces cache misses instead.
Local files
The helper checks local files before fetching remote outputs and stores new build outputs locally. The local directory isns-gocacheprog under NSC_CACHE_PATH when available, otherwise under the OS user cache directory. On Linux this is XDG_CACHE_HOME or ~/.cache; on macOS it is ~/Library/Caches. Set -cache-dir to choose a different parent directory:
GOCACHEPROG uses the helper’s local directory for build outputs, not the build-cache directory mounted by cache: go. The helper can still use the same Cache Volume through NSC_CACHE_PATH.
There is no automatic local eviction. Budget disk space for build outputs and downloads, and remove old helper cache files only when no Go process is using them. Remote eviction does not remove files already downloaded for an active build.
Persist configuration across workflow steps
In GitHub Actions, anexport affects only the current step. After installing the helper, add its configuration to GITHUB_ENV for subsequent steps:
Cache configuration
Use-concurrency to limit concurrent remote requests. The default is 4; supported values are 1 through 128. -namespace defaults to gocache and groups keys within the cache without creating a separate instance.
Verify cache use
The helper prints the same cache report at shutdown regardless of the backend.Get and Put show request counts, human-readable sizes, and p50/p90 latency. Actions shows local and remote misses and writes. Objects shows local disk hits, download wait time, and upload/download counts, sizes, and latency.
To check remote reuse, build the same source with the same Go version, platform, and build flags on a fresh machine or with a fresh -cache-dir. Running twice with the same local directory can demonstrate local reuse without exercising the remote cache.
Use -log-file to redirect helper logs or -silent to suppress the final statistics. To return to Go’s built-in cache in the current shell: