diff --git a/core/lib/Drupal/Component/PhpStorage/BootstrapStorageFactory.php b/core/lib/Drupal/Component/PhpStorage/BootstrapStorageFactory.php
new file mode 100644
index 0000000..91dc557
--- /dev/null
+++ b/core/lib/Drupal/Component/PhpStorage/BootstrapStorageFactory.php
@@ -0,0 +1,52 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Component\PhpStorage\BootstrapStorageFactory.
+ */
+
+
+namespace Drupal\Component\PhpStorage;
+
+
+use Drupal\Core\Cache\Cache;
+use Drupal\Core\Cache\DatabaseBackend;
+use Drupal\Core\Cache\DatabaseCacheTagsChecksum;
+use Drupal\Core\Database\Database;
+use Drupal\Core\Site\Settings;
+
+class BootstrapStorageFactory {
+
+  /**
+   * Returns a PHP storage implementation.
+   *
+   * @param $class_loader
+   *   The class loader. Normally Composer's ClassLoader, as included by the
+   *   front controller, but may also be decorated; e.g.,
+   *   \Symfony\Component\ClassLoader\ApcClassLoader.
+   *
+   * @return \Drupal\Component\PhpStorage\PhpStorageInterface
+   *   A PHP storage implementation.
+   */
+  public static function get($class_loader = NULL) {
+    $bootstrap_php_storage = Settings::get('bootstrap_php_storage');
+    $storage = FALSE;
+    if (!empty($bootstrap_php_storage) && is_callable($bootstrap_php_storage)) {
+      $storage = call_user_func($bootstrap_php_storage, $class_loader);
+    }
+    // Fallback to the DatabaseStorage.
+    return $storage ?: self::getDatabaseCacheStorage();
+  }
+
+  /**
+   * Returns a Database Cache based PHP storage implementation.
+   *
+   * @return \Drupal\Component\PhpStorage\CacheStorage
+   */
+  public static function getDatabaseCacheStorage() {
+    $connection = Database::getConnection();
+    $backend = new DatabaseBackend($connection, new DatabaseCacheTagsChecksum($connection), 'php_storage');
+    return new CacheStorage($backend, Settings::getHashSalt());
+  }
+
+}
diff --git a/core/lib/Drupal/Component/PhpStorage/CacheStorage.php b/core/lib/Drupal/Component/PhpStorage/CacheStorage.php
new file mode 100644
index 0000000..fc8d42a
--- /dev/null
+++ b/core/lib/Drupal/Component/PhpStorage/CacheStorage.php
@@ -0,0 +1,108 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Component\PhpStorage\CacheStorage.
+ */
+
+namespace Drupal\Component\PhpStorage;
+
+use Drupal\Component\Utility\OpCodeCache;
+use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Site\Settings;
+use Drupal\Core\StreamWrapper\SpecialCacheStream;
+
+/**
+ * This class stores PHP classes in a cache storage keeping it opcacheable.
+ */
+class CacheStorage implements PhpStorageInterface {
+
+  public function __construct(CacheBackendInterface $backend, $secret) {
+    $this->backend = $backend;
+    $this->secret = $secret;
+    $this->dir = Settings::get('cache_storage_dir') ?: sys_get_temp_dir();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function exists($name) {
+    $key = $this->getKeyFromFilename($name);
+    return (bool) $this->backend->get($key);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function load($name) {
+    $key = $this->getKeyFromFilename($name);
+    $cached = $this->backend->get($key);
+    if (!$cached) {
+      return FALSE;
+    }
+    $handle = fopen('php://memory', 'rwb');
+    fwrite($handle, $cached->data);
+    fseek($handle, 0);
+    stream_wrapper_unregister('phar');
+    stream_wrapper_register('phar', 'Drupal\Core\StreamWrapper\SpecialCacheStream');
+    SpecialCacheStream::init($handle, $cached->created);
+    $filename = SpecialCacheStream::MAGIC_NAME . $name;
+    #var_dump(opcache_is_script_cached($filename));
+    $return = (include $filename) !== FALSE;
+    stream_wrapper_restore('phar');
+    return $return;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function save($name, $code) {
+    $key = $this->getKeyFromFilename($name);
+    return $this->backend->set($key, $code);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function writeable() {
+    return TRUE;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function delete($name) {
+    $key = $this->getKeyFromFilename($name);
+    return $this->backend->delete($key);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function deleteAll() {
+    return $this->backend->deleteAll();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFullPath($name) {
+    return FALSE;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function listAll() {
+    // @TODO
+  }
+
+  /**
+   * @param $filename
+   * @return string
+   */
+  protected function getKeyFromFilename($filename) {
+    return hash_hmac('sha256', $filename, $this->secret);
+  }
+
+}
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 82afbaa..5507da0 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -8,6 +8,7 @@
 namespace Drupal\Core;
 
 use Drupal\Component\FileCache\FileCacheFactory;
+use Drupal\Component\PhpStorage\BootstrapStorageFactory;
 use Drupal\Component\ProxyBuilder\ProxyDumper;
 use Drupal\Component\Utility\Crypt;
 use Drupal\Component\Utility\Unicode;
@@ -1208,7 +1209,7 @@ protected function getHttpKernel() {
    */
   protected function storage() {
     if (!isset($this->storage)) {
-      $this->storage = PhpStorageFactory::get('service_container');
+      $this->storage = BootstrapStorageFactory::get($this->classLoader);
     }
     return $this->storage;
   }
diff --git a/core/lib/Drupal/Core/StreamWrapper/SpecialCacheStream.php b/core/lib/Drupal/Core/StreamWrapper/SpecialCacheStream.php
new file mode 100644
index 0000000..5ed915a
--- /dev/null
+++ b/core/lib/Drupal/Core/StreamWrapper/SpecialCacheStream.php
@@ -0,0 +1,144 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\StreamWrapper\SpecialCacheStream.
+ */
+
+namespace Drupal\Core\StreamWrapper;
+
+use Drupal\Core\Cache\CacheBackendInterface;
+
+class SpecialCacheStream {
+
+  const MAGIC_NAME = 'phar://core/core.api.php';
+
+  protected static $mtime;
+
+  /**
+   * Stream context resource.
+   *
+   * @var resource
+   */
+  public $context = NULL;
+
+  /**
+   * A generic resource handle.
+   *
+   * @var resource
+   */
+  protected static $handle = NULL;
+
+  public static function init($handle, $mtime) {
+    static::$handle = $handle;
+    static::$mtime = $mtime;
+  }
+
+  public function dir_closedir() {
+    throw new \BadMethodCallException('Not implemented');
+  }
+
+  public function dir_opendir($path) {
+    throw new \BadMethodCallException('Not implemented');
+  }
+
+  public function dir_readdir() {
+    throw new \BadMethodCallException('Not implemented');
+  }
+
+  public function dir_rewinddir() {
+    throw new \BadMethodCallException('Not implemented');
+  }
+
+  public function mkdir() {
+    throw new \BadMethodCallException('Not implemented');
+  }
+
+  public function rename() {
+    throw new \BadMethodCallException('Not implemented');
+  }
+
+  public function rmdir() {
+    throw new \BadMethodCallException('Not implemented');
+  }
+
+  public function stream_cast() {
+    return static::$handle ? static::$handle : FALSE;
+  }
+
+  public function stream_close () {
+    return fclose(static::$handle);
+  }
+
+  public function stream_eof() {
+    return feof(static::$handle);
+  }
+
+  public function stream_flush() {
+    return fflush(static::$handle);
+  }
+
+  public function stream_lock($operation) {
+    return flock(static::$handle, $operation);
+  }
+
+  public function stream_metadata($path, $option, $value) {
+    throw new \BadMethodCallException('Not implemented');
+  }
+
+  public function stream_open($path, $mode, $options) {
+    return TRUE;
+  }
+
+  public function stream_read($count) {
+    return fread(static::$handle, $count);
+  }
+
+  public function stream_seek($offset, $whence = SEEK_SET) {
+    return fseek(static::$handle, $offset, $whence);
+  }
+
+  public function stream_set_option() {
+    throw new \BadMethodCallException('Not implemented');
+  }
+
+  public function stream_stat() {
+    return fstat(static::$handle);
+  }
+
+  public function stream_tell() {
+    return ftell(static::$handle);
+  }
+
+  public function stream_truncate() {
+    throw new \BadMethodCallException('Not implemented');
+  }
+
+  public function stream_write($data) {
+    throw new \BadMethodCallException('Not implemented');
+  }
+
+  public function unlink($path) {
+    throw new \BadMethodCallException('Not implemented');
+  }
+
+  public function url_stat() {
+    $return = [
+      'dev' => 0,
+      'ino' => 0,
+      'mode' => 0,
+      'nlink' => 0,
+      'uid' => 0,
+      'gid' => 0,
+      'rdev' => 0,
+      'size' => 0,
+      'atime' => 0,
+      'mtime' => static::$mtime,
+      'ctime' => 0,
+      'blksize' => -1,
+      'blocks' => -1,
+    ];
+    return $return + array_values($return);
+  }
+
+}
