gocacheprog

command module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: BSD-2-Clause Imports: 22 Imported by: 0

README

gocacheprog

A tool to cache Go build artifacts in Redis. Implements protocol https://pkg.go.dev/cmd/go/internal/cacheprog.

Used in production and accelerated builds in Gitlab CI/CD by 4 times.

Installation

go install github.com/yonesko/gocacheprog@latest

Usage

The tool works as a proxy between go build and the file system, intercepting read/write requests for build artifacts. It uses local storage (a directory on disk) as the primary storage and Redis as an external cache for sharing artifacts between different builds.

Command Line Options
  • -dir - required parameter specifying the local directory for cache storage
  • -r-urls - comma-separated list of Redis server addresses
  • -r-usr - Redis username (optional)
  • -r-pwd - Redis password (optional)
  • -r-prefix - string to prefix Redis cache keys (optional)
  • -log-metrics - enable metrics logging (optional)
  • -log-req - enable request logging (optional)
  • -log-resp - enable response logging (optional)
Example Usage
GOCACHEPROG="gocacheprog -r-urls localhost:6379 -dir /tmp/cache" go build ./...

Architecture

The tool implements a three-tier data storage system:

  1. Local file storage - primary storage for artifacts
  2. Redis - external cache for sharing between builds
  3. If redis become unavailable this tool safely switches to local storage

When reading an artifact, the tool first checks the local storage, and if absent, downloads the data from Redis and saves it locally. When writing an artifact, it is saved simultaneously in both storages.

Benefits

  • Faster builds in CI/CD environments
  • Reduced network and disk load
  • Increased reliability through local backup

Documentation

Overview

Package main is a generated GoMock package.

Package cacheprog defines the protocol for a GOCACHEPROG program.

By default, the go command manages a build cache stored in the file system itself. GOCACHEPROG can be set to the name of a command (with optional space-separated flags) that implements the go command build cache externally. This permits defining a different cache policy.

The go command will start the GOCACHEPROG as a subprocess and communicate with it via JSON messages over stdin/stdout. The subprocess's stderr will be connected to the go command's stderr.

The subprocess should immediately send a Response with its capabilities. After that, the go command will send a stream of Request messages and the subprocess should reply to each Request with a Response message.

Jump to

Keyboard shortcuts

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