diff --git a/core/includes/common.inc b/core/includes/common.inc index 23f6ce3..cdcc70e 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -21,8 +21,10 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Site\Settings; -use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\StreamedResponse; use Drupal\Core\PhpStorage\PhpStorageFactory; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Datetime\DrupalDateTime; @@ -2684,8 +2686,20 @@ function _drupal_bootstrap_full($skip = FALSE) { * The request for this page. * * @see drupal_page_header() + * + * @return bool + * Returns TRUE if the response has been recorded in the cache, FALSE + * otherwise. */ function drupal_page_set_cache(Response $response, Request $request) { + // Currently it is not possible to cache some types of responses. Therefore + // exclude binary file responses (generated files, e.g. images with image + // styles) and streamed responses (files directly read from the disk). + // see: https://github.com/symfony/symfony/issues/9128#issuecomment-25088678 + if (($response instanceof BinaryFileResponse) || ($response instanceof StreamedResponse)) { + return FALSE; + } + // Check if the current page may be compressed. if (\Drupal::config('system.performance')->get('response.gzip') && !$response->headers->get('Content-Encoding') && extension_loaded('zlib')) { @@ -2709,6 +2723,8 @@ function drupal_page_set_cache(Response $response, Request $request) { $cid = drupal_page_cache_get_cid($request); $tags = HtmlViewSubscriber::convertHeaderToCacheTags($response->headers->get('X-Drupal-Cache-Tags')); \Drupal::cache('render')->set($cid, $response, $expire, $tags); + + return TRUE; } /** diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index 759ec91..7679a20 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -11,10 +11,8 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Site\Settings; -use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -82,11 +80,7 @@ public function onRespond(FilterResponseEvent $event) { $response->headers->set($name, $value, FALSE); } - // Currently it is not possible to cache some types of responses. Therefore - // exclude binary file responses (generated files, e.g. images with image - // styles) and streamed responses (files directly read from the disk). - // see: https://github.com/symfony/symfony/issues/9128#issuecomment-25088678 - $is_cacheable = drupal_page_is_cacheable() && !($response instanceof BinaryFileResponse) && !($response instanceof StreamedResponse); + $is_cacheable = drupal_page_is_cacheable(); // Add headers necessary to specify whether the response should be cached by // proxies and/or the browser. @@ -100,8 +94,7 @@ public function onRespond(FilterResponseEvent $event) { } // Store the response in the internal page cache. - if ($is_cacheable && $this->config->get('cache.page.use_internal')) { - drupal_page_set_cache($response, $request); + if ($is_cacheable && $this->config->get('cache.page.use_internal') && drupal_page_set_cache($response, $request)) { $response->headers->set('X-Drupal-Cache', 'MISS'); drupal_serve_page_from_cache($response, $request); } diff --git a/core/modules/image/src/Controller/ImageStyleDownloadController.php b/core/modules/image/src/Controller/ImageStyleDownloadController.php index 191a6c7..bf4f9d9 100644 --- a/core/modules/image/src/Controller/ImageStyleDownloadController.php +++ b/core/modules/image/src/Controller/ImageStyleDownloadController.php @@ -143,6 +143,7 @@ public function deliver(Request $request, $scheme, ImageStyleInterface $image_st } if ($success) { + drupal_page_is_cacheable(FALSE); $image = $this->imageFactory->get($derivative_uri); $uri = $image->getSource(); $headers += array(