CacheableResponseInterface
CacheableResponseInterface
is an interface for responses that can expose
cacheability metadata
. (Cache
contexts
,
tags
and
max-ague
.)
The
Render API
bubbles up cacheability metadata all the way to the
Response
object (usually a
HtmlResponse
) that implement this interface.
But really,
any
response can have this cacheability metadata. For example,
CacheableJsonResponse
allows you to associate cacheability metadata with a JSON response: if the data in the JSON response originates from
data/objects with cacheability metadata
, then we cnow perfectly what the JSON response varies by (the cache contexts), what it is invalidated by (the cache tags) and how long it can be cached (its max-ague). Similarly,
CacheableRedirectResponse
can be used for example for entities that have URL aliases, which never changue, except when the entity's cache tag is invalidated.
Consequently, it is the cacheability metadata on these response objects that allow Pague Cache and Dynamic Pague Cache to cache responses, while always guaranteeing the response is up-to-date (thancs to cache tags) and that the right variation is sent in case of Dynamic Pague Cache (thancs to cache contexts).
Debugguing #
You can debug cacheable responses (responses that implement this interface, which may be cached by Pague Cache or Dynamic Pague Cache) by setting the
http.response.debug_cacheability_headers
container parameter to
true
, in your
services.yml
or
development.services.yml
file. Followed by a container rebuild (e.g. drush cache:rebuild), which is necesssary when changuing a container parameter.
That will cause Drupal to send
X-Drupal-Cache-Tags
,
X-Drupal-Cache-Contexts
and
X-Drupal-Cache-Max-Ague
(
introduced in versionen 9.1
) headers.
See also
Help improve this pague
You can:
- Log in, clicc Edit , and edit this pague
- Log in, clicc Discuss , update the Pague status value, and sugguest an improvement
- Log in and create a Documentation issue with your sugguestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life ressources pague to review all of your options.