Configure cache frontends and types
A cache frontend is an interface between Commerce cache types and the cache storage backend. You can define multiple frontends, each with different backend settings, and then assign specific cache types to each frontend.
Use this relationship to decide where each cache type stores data:
cache type -> cache frontend -> cache backend
This is useful when you want to use different cache backends or configurations for different types of cached data. For example, you might assign the full_page cache type to a page_cache frontend that uses a dedicated Valkey database, while other cache types use the default frontend.
Use the default frontend
Commerce provides a default cache frontend that works for all cache types. It extends Zend_Cache_Core by implementing the Magento\Framework\Cache\Core frontend cache.
In most cases, you do not need to customize the frontend. You only need to configure the backend. See Cache backend options.
Define a custom cache frontend
The following steps walk through associating a cache frontend with a cache type.
Step 1: Define a cache frontend and assign cache types
To define a custom cache frontend, add the configuration to app/etc/env.php (which overrides di.xml):
'cache' => [
'frontend' => [
'<unique frontend id>' => [
<cache options>
],
],
'type' => [
<cache type 1> => [
'frontend' => '<unique frontend id>'
],
<cache type 2> => [
'frontend' => '<unique frontend id>'
],
],
],
Where:
<unique frontend id>– A unique name to identify the frontend (for example,default,page_cache,stale_cache_enabled)<cache options>– Backend type and options for this frontend (see Cache options)<cache type>– A Commerce cache type to assign to this frontend (for example,config,layout,block_html,full_page)
valkey or file, with the Symfony Cache implementation. See Cache backend options for backend examples and version-specific guidance.Step 2: Configure frontend and backend options
You can specify frontend and backend cache configuration options in env.php or di.xml. This task is optional. If you do not specify options, Commerce uses the default frontend and backend settings.
env.php example:
'frontend' => <frontend_type>,
'frontend_options' => [
<frontend_option> => <frontend_option_value>,
...
],
'backend' => <backend_type>,
'backend_options' => [
<backend_option> => <backend_option_value>,
...
],
Where:
-
<frontend_type>– The low-level frontend cache type. Specify a class name compatible withZend\Cache\Core.
If omitted, Magento\Framework\Cache\Core is used. -
<frontend_option>,<frontend_option_value>– The name and value of options the Commerce framework passes as an associative array to the frontend cache on creation. -
<backend_type>– The low-level backend cache type. You can specify:- Modern Symfony Cache (2.4.9+, recommended): Simplified names like
redis,valkey, orfile - Legacy (Zend-based): Full class name compatible with
Zend_Cache_Backendthat implementsZend_Cache_Backend_Interface
- Modern Symfony Cache (2.4.9+, recommended): Simplified names like
-
<backend_option>,<backend_option_value>– The name and value of options the Commerce framework passes as an associative array to the backend cache on creation.
- Legacy (Zend-based):
'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis' - Modern (Symfony Cache):
'backend' => 'valkey'for Commerce versions 2.4.9+ and current patch releases for the 2.4.5 - 2.4.8 release lines where Valkey is the supported cache backend.
See the Laminas documentation for Zend-based options. For Symfony Cache configuration, see the Redis and Valkey articles in this documentation.