Raised: $0
0% of monthly goal Help us cross the finish line!
Goal: $12,000
Raised: $0 Goal: $12,000
0% of monthly goal Help us cross the finish line!
Sponsor DDEV

If you find this add-on useful, please star it on GitHub — stars show appreciation and help maintainers know their work matters.

add-on registry tests last commit release

DDEV Global Cache

Overview

DDEV v1.25.6 gave each project its own cache volume, mounted at /mnt/ddev-project-cache, and stopped mounting the shared ddev-global-cache volume in the web container. Each project now downloads its packages again on its first install.

This add-on mounts ddev-global-cache back in web at /mnt/ddev-global-cache and points the package manager caches at it, as DDEV did before v1.25.6, so all projects with this add-on share them again:

Cache Location Set through
Composer /mnt/ddev-global-cache/composer COMPOSER_CACHE_DIR
npm /mnt/ddev-global-cache/npm npm_config_cache
corepack /mnt/ddev-global-cache/corepack COREPACK_HOME
pip /mnt/ddev-global-cache/pip PIP_CACHE_DIR
Yarn classic /mnt/ddev-global-cache/yarn/classic GLOBAL_CACHE_YARN_DIR, applied with yarn config set cache-folder
Yarn berry /mnt/ddev-global-cache/yarn/berry GLOBAL_CACHE_YARN_DIR, applied as the ~/.yarn/berry/cache symlink, used only with enableGlobalCache

The Yarn settings are applied by .ddev/web-entrypoint.d/global-cache.sh each time web starts.

Why

DDEV made caches per project for two reasons:

The package caches are a different case. With many projects, mostly on the same frameworks, separate caches mean:

This add-on shares only the package download caches, which mostly hold the same public packages for every project. Anything that holds credentials or per-project state, like Terminus or shell history, stays in the project cache.

Packages from private repositories are cached too, so every project with this add-on can read them. For a project where that matters, either remove the add-on from it with ddev add-on remove hanoii/ddev-global-cache, or keep only the caches that matter in the project, as below.

Tip

To keep a cache in the project, set its variable back to the path DDEV uses without this add-on, in .ddev/.env.web. For example, for private Composer packages:

# .ddev/.env.web
COMPOSER_CACHE_DIR=/mnt/ddev-project-cache/composer

The other caches work the same way:

Variable Per-project value
COMPOSER_CACHE_DIR /mnt/ddev-project-cache/composer
npm_config_cache /mnt/ddev-project-cache/npm
COREPACK_HOME /mnt/ddev-project-cache/corepack
PIP_CACHE_DIR /mnt/ddev-project-cache/pip
GLOBAL_CACHE_YARN_DIR /mnt/ddev-project-cache/yarn

Values in .ddev/.env.web replace the add-on’s, see Override Order. Run ddev restart afterwards.

These stay in the project cache:

The caches DDEV v1.25.5 and earlier left in ddev-global-cache are used again, so packages downloaded before the upgrade aren’t fetched again.

Apple container

DDEV is working on support for Apple’s native container runtime, through socktainer, which serves the Docker API on top of it (ddev/ddev#7372). It isn’t released yet.

Apple container runs each container in its own VM, and a named volume is an ext4 disk image attached to that VM. A volume can therefore be held read-write by one container, or read-only by any number of them, but not read-write by two. A second read-write attach fails with The storage device attachment is invalid. Apple closed this as working as designed: sharing would need a cluster filesystem (apple/container#1133).

ddev-global-cache was mounted read-write by web, db and the router of every project, so DDEV split it by writer (ddev/ddev#8895):

This add-on brings back exactly what Apple container can’t do: the web container of every project writes to ddev-global-cache. With it, a second project’s web can’t start while another project is running. Don’t install it in projects you run on Apple container.

Installation

ddev add-on get hanoii/ddev-global-cache
ddev restart

After installation, make sure to commit the .ddev directory to version control.

Requires DDEV v1.25.6 or newer. Earlier versions share these caches on their own.

Clearing the cache

The cache is shared by every project, and ddev delete doesn’t remove it. To clear it:

ddev poweroff
docker volume rm ddev-global-cache

DDEV recreates the volume on the next ddev start.

Credits

Contributed and maintained by @hanoii

If you find this add-on useful, please star it on GitHub — stars show appreciation and help maintainers know their work matters.