protected FinishResponseSubscriber::isCacheControlCustomized(Response $response)
Determine whether the given response has a custom Cache-Control header.
Upon construction, the ResponseHeaderBag is initialized with an empty Cache-Control header. Consequently it is not possible to check whether the header was set explicitly by simply checking its presence. Instead, it is necessary to examine the computed Cache-Control header and compare with values known to be present only when Cache-Control was never set explicitly.
When neither Cache-Control nor any of the ETag, Last-Modified, Expires headers are set on the response, ::get('Cache-Control') returns the value 'no-cache'. If any of ETag, Last-Modified or Expires are set but not Cache-Control, then 'private, must-revalidate' (in exactly this order) is returned.
Parameters
\Symfony\Component\HttpFoundation\Response $response:
Return value
bool TRUE when Cache-Control header was set explicitly on the given response.
See also
\Symfony\Component\HttpFoundation\ResponseHeaderBag::computeCacheControlValue()
File
- core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php, line 188
Class
- FinishResponseSubscriber
- Response subscriber to handle finished responses.
Namespace
Drupal\Core\EventSubscriber
Code
protected function isCacheControlCustomized(Response $response) { $cache_control = $response->headers->get('Cache-Control'); return $cache_control != 'no-cache' && $cache_control != 'private, must-revalidate'; }
Please login to continue.