Symfony stores both system and application caches under the var/cache/ dir. However, these two types of caches have conflicting requirements in multi-server architectures:
- System caches (compiled container, routes, optimized classes, etc.) should be local to each server for maximum performance. They don't need to be synchronized across servers because they're identical on every instance.
- Application caches (like cache.app pools) need to be shared between all servers in a cluster to maintain data consistency.
The current workaround is to mount the entire var/cache/ directory on shared
storage (NFS, EFS, etc.). This works, but it hurts performance because it forces
system caches to use slow network storage instead of fast local disks.
In Symfony 7.4, we're introducing a new concept that solves this problem: the share directory. It's a dedicated directory for data that must be shared between servers.
This new directory is available through:
- A new
KernelInterface::getShareDir()method - A new
APP_SHARE_DIRenvironment variable - A new
%kernel.share_dir%parameter
For backward compatibility, getShareDir() returns the same value as
getCacheDir() by default. In new Symfony 7.4 applications, the .env file
will define this variable:
APP_SHARE_DIR=$APP_PROJECT_DIR/var/share
All cache pools derived from the app cache adapter now default to storing
their data in %kernel.share_dir%/pools/app instead of %kernel.cache_dir%/pools/app.
However, the share directory is not limited to cache pools. It's meant for any
data that should be shared across all frontend servers in a cluster. For example:
var/share/pools/(application cache pools)var/share/http_cache/(HTTP cache storage)var/share/storage/(Flysystem local storage)var/share/db/(SQLite databases)