diff --git a/core/includes/common.inc b/core/includes/common.inc index dd7bc8cac7f..cd215122fc8 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -5242,7 +5242,7 @@ function _drupal_bootstrap_full() { * * @see drupal_page_header() */ -function drupal_page_set_cache() { +function drupal_page_set_cache($response_body) { global $base_root; if (drupal_page_is_cacheable()) { @@ -5250,7 +5250,7 @@ function drupal_page_set_cache() { 'cid' => $base_root . request_uri(), 'data' => array( 'path' => $_GET['q'], - 'body' => ob_get_clean(), + 'body' => $response_body, 'title' => drupal_get_title(), 'headers' => array(), ), diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 33fe6462b9e..2e3838bfa37 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -24,6 +24,7 @@ use Drupal\Core\EventSubscriber\AccessSubscriber; use Drupal\Core\EventSubscriber\PathSubscriber; use Drupal\Core\EventSubscriber\LegacyControllerSubscriber; use Drupal\Core\EventSubscriber\MaintenanceModeSubscriber; +use Drupal\Core\EventSubscriber\ResponseSubscriber; use Exception; @@ -74,6 +75,7 @@ class DrupalKernel extends HttpKernel { $this->dispatcher->addSubscriber(new MaintenanceModeSubscriber()); $this->dispatcher->addSubscriber(new PathSubscriber()); $this->dispatcher->addSubscriber(new LegacyControllerSubscriber()); + $this->dispatcher->addSubscriber(new ResponseSubscriber()); // Some other form of error occured that wasn't handled by another kernel // listener. That could mean that it's a method/mime-type/error diff --git a/core/lib/Drupal/Core/EventSubscriber/ResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ResponseSubscriber.php new file mode 100644 index 00000000000..e00f0af1c06 --- /dev/null +++ b/core/lib/Drupal/Core/EventSubscriber/ResponseSubscriber.php @@ -0,0 +1,67 @@ +getResponse(); + $config = config('system.performance'); + + if ($config->get('cache') && ($cache = drupal_page_set_cache($response->getContent()))) { + drupal_serve_page_from_cache($cache); + } + else { + ob_flush(); + } + + _registry_check_code(REGISTRY_WRITE_LOOKUP_CACHE); + drupal_cache_system_paths(); + module_implements_write_cache(); + system_run_automated_cron(); + } + + /** + * Registers the methods in this class that should be listeners. + * + * @return array + * An array of event listener definitions. + */ + static function getSubscribedEvents() { + $events[KernelEvents::RESPONSE][] = array('onKernelResponse'); + + return $events; + } +}