diff --git a/core/includes/common.inc b/core/includes/common.inc
index dd7bc8cac7f1a02192043b7cccf9ffacb58118e6..cd215122fc82bab03ac1f9bd4702ab5960583422 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 33fe6462b9e61bf464c55adc9f0269e9ff0f04ba..2e3838bfa378ba70c8a4e402629a3cb945b39f70 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -24,6 +24,7 @@
 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 @@ public function __construct(EventDispatcherInterface $dispatcher, ControllerReso
       $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 0000000000000000000000000000000000000000..e00f0af1c068130dcb6c75fab89ef5387ae14b8f
--- /dev/null
+++ b/core/lib/Drupal/Core/EventSubscriber/ResponseSubscriber.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Drupal\Core\EventSubscriber;
+
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+
+/**
+ * @file
+ *
+ * Definition of Drupal\Core\EventSubscriber\ResponseSubscriber;
+ */
+
+/**
+ * Subscriber for all responses.
+ */
+class ResponseSubscriber implements EventSubscriberInterface {
+
+  /**
+   * Performs end of request tasks.
+   *
+   * @todo The body of this function has just been copied almost verbatim from
+   * drupal_page_footer(), with the exception of now passing the response
+   * content to drupal_page_set_cache(). There's probably a lot in here that
+   * needs to get removed/changed.
+   *
+   * @param FilterResponseEvent $event
+   *   The Event to process.
+   */
+  public function onKernelResponse(FilterResponseEvent $event) {
+
+    global $user;
+    module_invoke_all('exit');
+
+    // Commit the user session, if needed.
+    drupal_session_commit();
+    $response = $event->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;
+  }
+}