diff --git a/core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php b/core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php
index 1a460ad..055d39c 100644
--- a/core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php
+++ b/core/lib/Drupal/Component/PhpStorage/FileReadOnlyStorage.php
@@ -34,16 +34,9 @@ public function __construct(array $configuration) {
   }
 
   /**
-   * Implements Drupal\Component\PhpStorage\PhpStorageInterface::exists().
-   */
-  public function exists($name) {
-    return file_exists($this->getFullPath($name));
-  }
-
-  /**
    * Implements Drupal\Component\PhpStorage\PhpStorageInterface::load().
    */
-  public function load($name) {
+  public function load($name, $class_name = NULL, $wait = 200, $retry = 5) {
     // The FALSE returned on failure is enough for the caller to handle this,
     // we do not want a warning too.
     return (@include_once $this->getFullPath($name)) !== FALSE;
diff --git a/core/lib/Drupal/Component/PhpStorage/FileStorage.php b/core/lib/Drupal/Component/PhpStorage/FileStorage.php
index 71ff3f2..06e3149 100644
--- a/core/lib/Drupal/Component/PhpStorage/FileStorage.php
+++ b/core/lib/Drupal/Component/PhpStorage/FileStorage.php
@@ -33,19 +33,36 @@ public function __construct(array $configuration) {
   }
 
   /**
-   * Implements Drupal\Component\PhpStorage\PhpStorageInterface::exists().
+   * Implements Drupal\Component\PhpStorage\PhpStorageInterface::load().
    */
-  public function exists($name) {
-    return file_exists($this->getFullPath($name));
+  public function load($name, $class_name = NULL, $wait = 200, $retry = 5) {
+    if ($class_name) {
+      while (!($exists = class_exists($class_name, FALSE)) && $this->doLoad($name, TRUE) && !($exists = class_exists($class_name, FALSE)) && $retry--) {
+        usleep(mt_rand($wait, 2 * $wait));
+      }
+      return $exists;
+    }
+    // The FALSE returned on failure is enough for the caller to handle this,
+    // we do not want a warning too.
+    return $this->doLoad($name, FALSE);
   }
 
   /**
-   * Implements Drupal\Component\PhpStorage\PhpStorageInterface::load().
+   * Do the actual loading.
+   *
+   * @param $name
+   *   The name of the file.
+   * @param $class_loading
+   *   TRUE if a class is being loadded and it does not exist.
+   *
+   * @return bool
+   *   TRUE on success, FALSE otherwise.
    */
-  public function load($name) {
-    // The FALSE returned on failure is enough for the caller to handle this,
-    // we do not want a warning too.
-    return (@include_once $this->getFullPath($name)) !== FALSE;
+  protected function doLoad($name, $class_loading) {
+    $success = $class_loading ?
+      @include $this->getFullPath($name) :
+      @include_once $this->getFullPath($name);
+    return $success !== FALSE;
   }
 
   /**
diff --git a/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFileStorage.php b/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFileStorage.php
index 573e23c..45234cd 100644
--- a/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFileStorage.php
+++ b/core/lib/Drupal/Component/PhpStorage/MTimeProtectedFileStorage.php
@@ -36,14 +36,17 @@
 class MTimeProtectedFileStorage extends MTimeProtectedFastFileStorage {
 
   /**
-   * Implements Drupal\Component\PhpStorage\PhpStorageInterface::load().
+   * {@inheritdoc}}
    */
-  public function load($name) {
+  protected function doLoad($name, $class_loading) {
+    $success = FALSE;
     if (($filename = $this->checkFile($name)) !== FALSE) {
       // Inline parent::load() to avoid an expensive getFullPath() call.
-      return (@include_once $filename) !== FALSE;
+      $success = $class_loading ?
+        @include $filename :
+        @include_once $filename;
     }
-    return FALSE;
+    return $success !== FALSE;
   }
 
   /**
diff --git a/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php
index 1f6a682..43fa379 100644
--- a/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php
+++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php
@@ -19,17 +19,6 @@
 interface PhpStorageInterface {
 
   /**
-   * Checks whether the PHP code exists in storage.
-   *
-   * @param string $name
-   *   The virtual file name. Can be a relative path.
-   *
-   * @return bool
-   *   TRUE if the virtual file exists, FALSE otherwise.
-   */
-  public function exists($name);
-
-  /**
    * Loads PHP code from storage.
    *
    * Depending on storage implementation, exists() checks can be expensive, so
@@ -40,8 +29,20 @@ public function exists($name);
    *
    * @param string $name
    *   The virtual file name. Can be a relative path.
+   * @param string $class_name
+   *   A class name to verify after loading. In a race condition, the file
+   *   might exist but not contain the right value.
+   * @param int $wait
+   *   If the class name is specified and the the file is found but the class
+   *   does not exist a random amount of time between $wait and 2 * $wait
+   *   milliseconds before returning to allow the reacing process to finish.
+   * @param int $retry
+   *   The number of times to retry waiting and reloading.
+   *
+   * @return
+   *   TRUE on success, FALSE otherwise.
    */
-  public function load($name);
+  public function load($name, $class_name = NULL, $wait = 200, $retry = 5);
 
   /**
    * Saves PHP code to storage.
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 557dfd1..cd1e047d 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -720,11 +720,12 @@ protected function initializeContainer($rebuild = FALSE) {
     // If the module list hasn't already been set in updateModules and we are
     // not forcing a rebuild, then try and load the container from the disk.
     if (empty($this->moduleList) && !$rebuild) {
-      $fully_qualified_class_name = '\\' . $this->getClassNamespace() . '\\' . $this->getClassName();
+      $class_name = $this->getClassName();
+      $fully_qualified_class_name = '\\' . $this->getClassNamespace() . '\\' . $class_name;
 
       // First, try to load from storage.
       if (!class_exists($fully_qualified_class_name, FALSE)) {
-        $this->storage()->load($this->getClassName() . '.php');
+        $this->storage()->load($class_name . '.php', $class_name);
       }
       // If the load succeeded or the class already existed, use it.
       if (class_exists($fully_qualified_class_name, FALSE)) {
diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php
index 9225712..bb64757 100644
--- a/core/lib/Drupal/Core/Template/TwigEnvironment.php
+++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php
@@ -127,9 +127,9 @@ public function loadTemplate($name, $index = NULL) {
           $this->updateCompiledTemplate($cache_filename, $name);
         }
 
-        if (!$this->storage()->load($cache_filename)) {
+        if (!$this->storage()->load($cache_filename, $cls)) {
           $this->updateCompiledTemplate($cache_filename, $name);
-          $this->storage()->load($cache_filename);
+          $this->storage()->load($cache_filename, $cls);
         }
       }
     }
diff --git a/core/modules/system/src/Tests/Theme/TwigSettingsTest.php b/core/modules/system/src/Tests/Theme/TwigSettingsTest.php
index 36cc48d..0ab9773 100644
--- a/core/modules/system/src/Tests/Theme/TwigSettingsTest.php
+++ b/core/modules/system/src/Tests/Theme/TwigSettingsTest.php
@@ -105,7 +105,7 @@ function testTwigCacheOverride() {
 
     // Navigate to the page and make sure the template gets cached.
     $this->drupalGet('theme-test/template-test');
-    $this->assertTrue(PhpStorageFactory::get('twig')->exists($cache_filename), 'Cached Twig template found.');
+    $this->assertTrue(PhpStorageFactory::get('twig')->load($cache_filename), 'Cached Twig template found.');
 
     // Disable the Twig cache and rebuild the service container.
     $parameters = $this->container->getParameter('twig.config');
diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php
index 8cf9642..2516465 100644
--- a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php
+++ b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageReadOnlyTest.php
@@ -71,7 +71,7 @@ public function testReadOnly() {
 
     // If the file was successfully loaded, it must also exist, but ensure the
     // exists() method returns that correctly.
-    $this->assertSame($php_read->exists($name), TRUE);
+    $this->assertSame($php_read->load($name), TRUE);
     // Saving and deleting should always fail.
     $this->assertFalse($php_read->save($name, $code));
     $this->assertFalse($php_read->delete($name));
