cache.yml configuration file describes the cache configuration for the
view layer. This configuration file is only active if the
cache setting is enabled in
When an application is created, symfony generates a default
in the application
config/ directory which describes the cache for the whole
application (under the
default key). By default, the cache is globally set
default: enabled: false with_layout: false lifetime: 86400
enabled setting is set to
false by default, you need to
enable the cache selectively. You can also work the other way around:
enable the cache globally and then, disable it on specific pages that
cannot be cached. Your approach should depend on what represents less work
for your application.
cache.yml configuration file is cached as a PHP file; the
process is automatically managed by the
The default application configuration can be overridden for a module by
cache.yml file in the
config/ directory of the module. The main
keys are action names without the
execute prefix (
index for the
executeIndex method for instance). A partial or component can also be cached
by using its name prefixed with an underscore (
To determine if an action is cached or not, symfony looks for the information in the following order:
a configuration for the specific action, partial, or component in the module configuration file, if it exists;
a configuration for the whole module in the module configuration file, if it exists (under the
the default application configuration (under the
An incoming request with
GET parameters in the query string or
submitted with the
DELETE method will never be
cached by symfony, regardless of the configuration.
enabled setting enables or disables the cache for the current scope.
with_layout setting determines whether the cache must be for the entire
true), or for the action only (
with_layout option is not taken into account for partial and
component caching as they cannot be decorated by a layout.
lifetime setting defines the server-side lifetime of the cache in
86400 seconds equals one day).
Default: Same value as the
client_lifetime setting defines the client-side lifetime of the cache in
This setting is used to automatically set the
Expires header and the
max-cache cache control variable, unless a
header has already been set.
You can disable client-side caching by setting the value to
contextual setting determines if the cache depends on the current page
context or not. The setting is therefore only meaningful when used for
partials and components.
When a partial output is different depending on the template in which it is
included, the partial is said to be contextual, and the
must be set to
true. By default, the setting is set to
false, which means
that the output for partials and components are always the same, wherever it
The cache is still obviously different for a different set of parameters.