diff --git a/core/core.services.yml b/core/core.services.yml
index c56c778..4b6b33f 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -397,7 +397,9 @@ services:
     factory: Drupal\Core\Site\Settings::getInstance
   state:
     class: Drupal\Core\State\State
-    arguments: ['@keyvalue']
+    arguments: ['@keyvalue', '@cache.bootstrap', '@lock']
+    tags:
+      - { name: needs_destruction }
   queue:
     class: Drupal\Core\Queue\QueueFactory
     arguments: ['@settings']
diff --git a/core/lib/Drupal/Core/Cache/MemoryBackend.php b/core/lib/Drupal/Core/Cache/MemoryBackend.php
index 5c7f928..3b680bf 100644
--- a/core/lib/Drupal/Core/Cache/MemoryBackend.php
+++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php
@@ -164,7 +164,9 @@ public function invalidate($cid) {
    */
   public function invalidateMultiple(array $cids) {
     foreach ($cids as $cid) {
-      $this->cache[$cid]->expire = $this->getRequestTime() - 1;
+      if (isset($this->cache[$cid])) {
+        $this->cache[$cid]->expire = $this->getRequestTime() - 1;
+      }
     }
   }
 
diff --git a/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php
index 9c3cfae..95d4d3b 100644
--- a/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php
@@ -64,7 +64,10 @@ public function onKernelTerminate(PostResponseEvent $event) {
    *   An array of event listener definitions.
    */
   static function getSubscribedEvents() {
-    $events[KernelEvents::TERMINATE][] = array('onKernelTerminate', 100);
+    // Run this subscriber after others as those might use services that need
+    // to be terminated as well or run code that needs to run before
+    // termination.
+    $events[KernelEvents::TERMINATE][] = array('onKernelTerminate', -100);
     return $events;
   }
 }
diff --git a/core/lib/Drupal/Core/State/State.php b/core/lib/Drupal/Core/State/State.php
index 5da5241..bb1640e 100644
--- a/core/lib/Drupal/Core/State/State.php
+++ b/core/lib/Drupal/Core/State/State.php
@@ -7,12 +7,15 @@
 
 namespace Drupal\Core\State;
 
+use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Cache\CacheCollector;
 use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
+use Drupal\Core\Lock\LockBackendInterface;
 
 /**
  * Provides the state system using a key value store.
  */
-class State implements StateInterface {
+class State extends CacheCollector implements StateInterface {
 
   /**
    * The key value store to use.
@@ -22,19 +25,17 @@ class State implements StateInterface {
   protected $keyValueStore;
 
   /**
-   * Static state cache.
-   *
-   * @var array
-   */
-  protected $cache = array();
-
-  /**
    * Constructs a State object.
    *
    * @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory
    *   The key value store to use.
+   * @param \Drupal\Core\Cache\CacheBackendInterface $cache
+   *   The cache backend.
+   * @param \Drupal\Core\Lock\LockBackendInterface $lock
+   *   The lock backend.
    */
-  function __construct(KeyValueFactoryInterface $key_value_factory) {
+  public function __construct(KeyValueFactoryInterface $key_value_factory, CacheBackendInterface $cache, LockBackendInterface $lock) {
+    parent::__construct('state', $cache, $lock);
     $this->keyValueStore = $key_value_factory->get('state');
   }
 
@@ -42,8 +43,18 @@ function __construct(KeyValueFactoryInterface $key_value_factory) {
    * {@inheritdoc}
    */
   public function get($key, $default = NULL) {
-    $values = $this->getMultiple(array($key));
-    return isset($values[$key]) ? $values[$key] : $default;
+    $value = parent::get($key);
+    return $value !== NULL ? $value : $default;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function resolveCacheMiss($key) {
+    $value = $this->keyValueStore->get($key);
+    $this->storage[$key] = $value;
+    $this->persist($key);
+    return $value;
   }
 
   /**
@@ -51,33 +62,9 @@ public function get($key, $default = NULL) {
    */
   public function getMultiple(array $keys) {
     $values = array();
-    $load = array();
     foreach ($keys as $key) {
-      // Check if we have a value in the cache.
-      if (isset($this->cache[$key])) {
-        $values[$key] = $this->cache[$key];
-      }
-      // Load the value if we don't have an explicit NULL value.
-      elseif (!array_key_exists($key, $this->cache)) {
-        $load[] = $key;
-      }
+      $values[$key] = $this->get($key);
     }
-
-    if ($load) {
-      $loaded_values = $this->keyValueStore->getMultiple($load);
-      foreach ($load as $key) {
-        // If we find a value, even one that is NULL, add it to the cache and
-        // return it.
-        if (isset($loaded_values[$key]) || array_key_exists($key, $loaded_values)) {
-          $values[$key] = $loaded_values[$key];
-          $this->cache[$key] = $loaded_values[$key];
-        }
-        else {
-          $this->cache[$key] = NULL;
-        }
-      }
-    }
-
     return $values;
   }
 
@@ -85,7 +72,7 @@ public function getMultiple(array $keys) {
    * {@inheritdoc}
    */
   public function set($key, $value) {
-    $this->cache[$key] = $value;
+    parent::set($key, $value);
     $this->keyValueStore->set($key, $value);
   }
 
@@ -94,7 +81,7 @@ public function set($key, $value) {
    */
   public function setMultiple(array $data) {
     foreach ($data as $key => $value) {
-      $this->cache[$key] = $value;
+      parent::set($key, $value);
     }
     $this->keyValueStore->setMultiple($data);
   }
@@ -103,6 +90,7 @@ public function setMultiple(array $data) {
    * {@inheritdoc}
    */
   public function delete($key) {
+    parent::delete($key);
     $this->deleteMultiple(array($key));
   }
 
@@ -111,7 +99,7 @@ public function delete($key) {
    */
   public function deleteMultiple(array $keys) {
     foreach ($keys as $key) {
-      unset($this->cache[$key]);
+      parent::delete($key);
     }
     $this->keyValueStore->deleteMultiple($keys);
   }
@@ -120,7 +108,7 @@ public function deleteMultiple(array $keys) {
    * {@inheritdoc}
    */
   public function resetCache() {
-    $this->cache = array();
+    $this->clear();
   }
 
 }
diff --git a/core/modules/system/src/Tests/Routing/MatcherDumperTest.php b/core/modules/system/src/Tests/Routing/MatcherDumperTest.php
index f98d294..61bd64c 100644
--- a/core/modules/system/src/Tests/Routing/MatcherDumperTest.php
+++ b/core/modules/system/src/Tests/Routing/MatcherDumperTest.php
@@ -7,7 +7,9 @@
 
 namespace Drupal\system\Tests\Routing;
 
+use Drupal\Core\Cache\MemoryBackend;
 use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
+use Drupal\Core\Lock\NullLockBackend;
 use Drupal\Core\State\State;
 use Drupal\simpletest\KernelTestBase;
 use Symfony\Component\Routing\Route;
@@ -41,7 +43,7 @@ protected function setUp() {
     parent::setUp();
 
     $this->fixtures = new RoutingFixtures();
-    $this->state = new State(new KeyValueMemoryFactory());
+    $this->state = new State(new KeyValueMemoryFactory(), new MemoryBackend('test'), new NullLockBackend());;
   }
 
   /**
diff --git a/core/modules/system/src/Tests/Routing/RouteProviderTest.php b/core/modules/system/src/Tests/Routing/RouteProviderTest.php
index c1d24ff..7e469cb 100644
--- a/core/modules/system/src/Tests/Routing/RouteProviderTest.php
+++ b/core/modules/system/src/Tests/Routing/RouteProviderTest.php
@@ -11,6 +11,7 @@
 use Drupal\Core\Database\Database;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
+use Drupal\Core\Lock\NullLockBackend;
 use Drupal\Core\Path\CurrentPathStack;
 use Drupal\Core\Routing\MatcherDumper;
 use Drupal\Core\Routing\RouteProvider;
@@ -81,7 +82,7 @@ class RouteProviderTest extends KernelTestBase {
   protected function setUp() {
     parent::setUp();
     $this->fixtures = new RoutingFixtures();
-    $this->state = new State(new KeyValueMemoryFactory());
+    $this->state = new State(new KeyValueMemoryFactory(), new MemoryBackend('test'), new NullLockBackend());
     $this->currentPath = new CurrentPathStack(new RequestStack());
     $this->cache = new MemoryBackend('data');
     $this->pathProcessor = \Drupal::service('path_processor_manager');
diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php
index 4653f13..18a143f 100644
--- a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php
+++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php
@@ -7,10 +7,12 @@
 
 namespace Drupal\Tests\Core\Extension;
 
+use Drupal\Core\Cache\MemoryBackend;
 use Drupal\Core\Extension\Extension;
 use Drupal\Core\Extension\InfoParser;
 use Drupal\Core\Extension\ThemeHandler;
 use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
+use Drupal\Core\Lock\NullLockBackend;
 use Drupal\Core\State\State;
 use Drupal\Tests\UnitTestCase;
 
@@ -78,7 +80,7 @@ protected function setUp() {
       ),
     ));
     $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
-    $this->state = new State(new KeyValueMemoryFactory());
+    $this->state = new State(new KeyValueMemoryFactory(), new MemoryBackend('test'), new NullLockBackend());
     $this->infoParser = $this->getMock('Drupal\Core\Extension\InfoParserInterface');
     $this->extensionDiscovery = $this->getMockBuilder('Drupal\Core\Extension\ExtensionDiscovery')
       ->disableOriginalConstructor()
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
index c621e62..9e7b0c1 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
@@ -9,6 +9,7 @@
 
 use Drupal\Core\Cache\MemoryBackend;
 use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
+use Drupal\Core\Lock\NullLockBackend;
 use Drupal\Core\Render\Element;
 use Drupal\Core\Render\Renderer;
 use Drupal\Core\State\State;
@@ -504,7 +505,7 @@ public function testBubblingWithPrerender($test_element) {
     $this->setupMemoryCache();
 
     // Mock the State service.
-    $memory_state = new State(new KeyValueMemoryFactory());;
+    $memory_state = new State(new KeyValueMemoryFactory(), new MemoryBackend('test'), new NullLockBackend());
     \Drupal::getContainer()->set('state', $memory_state);
     $this->controllerResolver->expects($this->any())
       ->method('getControllerFromDefinition')
diff --git a/index.php b/index.php
index 750dc28..cdd85c8 100644
--- a/index.php
+++ b/index.php
@@ -8,6 +8,11 @@
  * See COPYRIGHT.txt and LICENSE.txt files in the "core" directory.
  */
 
+$uprofiler_path = '/var/www/html';
+include_once $uprofiler_path . '/uprofiler_lib/utils/uprofiler_lib.php';
+include_once $uprofiler_path . '/uprofiler_lib/utils/uprofiler_runs.php';
+uprofiler_enable(UPROFILER_FLAGS_NO_BUILTINS + UPROFILER_FLAGS_MEMORY);
+
 use Drupal\Core\DrupalKernel;
 use Symfony\Component\HttpFoundation\Request;
 
@@ -20,3 +25,9 @@
 $response->send();
 
 $kernel->terminate($request, $response);
+
+$uprofiler_data = uprofiler_disable();
+$uprofiler_runs = new uprofilerRuns_Default();
+$namespace = 'd8';
+$id = $uprofiler_runs->save_run($uprofiler_data, $namespace);
+print "<a href='http://localhost/uprofiler_html/?run=$id&sort=excl_wt&source=$namespace'>uprofiler</a>";
