If you find this add-on useful, please star it on GitHub — stars show appreciation and help maintainers know their work matters.
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.
DDEV made caches per project for two reasons:
container, which can’t share a volume that more than
one container writes to. See Apple container below.The package caches are a different case. With many projects, mostly on the same frameworks, separate caches mean:
ddev delete removes the project cache, so deleting and recreating a project
starts from nothing.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:
n Node.js downloads: they were already kept per
project before v1.25.6.Terminus: its cache holds the Pantheon login, which DDEV moved to the project
cache so one project’s login doesn’t carry into others. To share it anyway,
set TERMINUS_CACHE_DIR in the project:
ddev config --web-environment-add=TERMINUS_CACHE_DIR=/mnt/ddev-global-cache/terminus/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.
containerDDEV 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):
web and db got a cache volume each, per project, shipped in v1.25.6
(ddev/ddev#9024).web instead of mounted
(ddev/ddev#9045).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.
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.
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.
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.