Every package build downloads its dependencies from the internet: Go modules, Python wheels, npm packages, Maven JARs, and so on. When you run the same build repeatedly — during iteration or in CI — those downloads are wasted time. melange’s build cache feature lets you mount a directory from your host into the build environment atDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/chainguard-dev/melange/llms.txt
Use this file to discover all available pages before exploring further.
/var/cache/melange, so subsequent builds can reuse artefacts that were fetched before.
How the cache works
Pass--cache-dir to melange build with a path to a directory on your local filesystem:
/var/cache/melange. Build tools that are configured to look there will find cached artefacts instead of downloading them. For several ecosystems — Python uv, pip, PHP Composer, and npm — melange sets the relevant environment variables automatically so no extra configuration is needed.
Whether writes to
/var/cache/melange during a build flow back to your host filesystem depends on which runner you use. See Cache Persistence by Runner below.Go modules
Go does not set its module cache automatically; you must tell it where to look. If you already have Go installed locally, you can pass your existing module cache directly:GOMODCACHE environment variable inside your melange config so the Go toolchain inside the guest finds the cache:
Python uv
melange automatically setsUV_CACHE_DIR=/var/cache/melange/uv. Simply point --cache-dir at a directory that contains (or will contain) a uv subdirectory:
Python pip
melange automatically setsPIP_CACHE_DIR=/var/cache/melange/pip. No YAML changes are required:
PHP Composer
melange automatically setsCOMPOSER_CACHE_DIR=/var/cache/melange/composer:
npm
melange automatically setsnpm_config_cache=/var/cache/melange/npm:
Maven
Maven caching is activated automatically when you use themaven/configure-mirror or maven/pombump built-in pipelines. When a cache directory is mounted at /var/cache/melange, those pipelines symlink ~/.m2/repository to /var/cache/melange/m2repository, so Maven’s default local repository is backed by the cache with no extra configuration:
apicurio-registry requires over 1 GB of Maven dependencies.
Cache persistence by runner
Whether writes to/var/cache/melange during a build flow back to your host depends on the runner:
| Runner | Mount type | Writes persist to host |
|---|---|---|
| Docker | Bind mount (read-write) | Yes |
| Bubblewrap | Bind mount (read-write) | Yes |
| QEMU (default) | 9p (read-only) + overlay | No |
| QEMU (virtiofs) | virtiofs (read-write) | Yes |
Docker and Bubblewrap
Both runners use a standard read-write bind mount. Any files written to/var/cache/melange during the build are written directly to your host directory, so the cache grows automatically across builds.
QEMU (default, without virtiofs)
The default QEMU runner mounts the cache using 9p with a read-only flag and layers a temporary overlay on top:- Lower layer: Read-only 9p mount of your host cache directory
- Upper layer: Temporary writable directory inside the guest
QEMU with virtiofs
Enable virtiofs by setting theQEMU_USE_VIRTIOFS environment variable:
- Cache persistence — writes during the build are saved to your host filesystem.
- Better I/O performance — virtiofs generally outperforms 9p for build workloads.
Preloading a cache from a remote source
For CI environments, you can pre-populate a cache directory from a remote bucket or another directory using the--cache-source flag:
--cache-dir before the build begins, letting the build immediately benefit from previously cached artefacts.