diff --git a/core/includes/common.inc b/core/includes/common.inc index 037c5b0..99738af 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1100,7 +1100,7 @@ function drupal_flush_all_caches() { \Drupal::service('kernel')->invalidateContainer(); // Wipe the Twig PHP Storage cache. - PhpStorageFactory::get('twig')->deleteAll(); + PhpStorageFactory::deleteAll(); // Rebuild module and theme data. $module_data = system_rebuild_module_data(); diff --git a/core/includes/utility.inc b/core/includes/utility.inc index 2bb6507..7b343b6 100644 --- a/core/includes/utility.inc +++ b/core/includes/utility.inc @@ -29,7 +29,7 @@ function drupal_rebuild(ClassLoader $class_loader, Request $request) { restore_exception_handler(); // Force kernel to rebuild php cache. - PhpStorageFactory::get('twig')->deleteAll(); + PhpStorageFactory::deleteAll(); // Bootstrap up to where caches exist and clear them. $kernel = new DrupalKernel('prod', $class_loader); diff --git a/core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php b/core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php index e76e27f..3ec4ac0 100644 --- a/core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php +++ b/core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php @@ -2,6 +2,7 @@ namespace Drupal\Core\PhpStorage; +use Drupal\Component\Utility\Crypt; use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\PublicStream; @@ -40,7 +41,14 @@ static function get($name) { // Make sure all the necessary configuration values are set. $class = isset($configuration['class']) ? $configuration['class'] : 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage'; if (!isset($configuration['secret'])) { - $configuration['secret'] = Settings::getHashSalt(); + $secret = Settings::getHashSalt(); + if ($cache = \Drupal::cache('bootstrap')->get('phpstorage_hash')) { + $secret .= $cache->data; + } + elseif ($state = \Drupal::state()->get('phpstorage_hash')) { + $secret .= $state; + } + $configuration['secret'] = $secret; } if (!isset($configuration['bin'])) { $configuration['bin'] = $name; @@ -51,4 +59,11 @@ static function get($name) { return new $class($configuration); } + public static function deleteAll() { + // Generate a new hash which allows to distribute truncations of phpstorage + // across multiple webheads. + \Drupal::state()->set('phpstorage_hash', Crypt::randomBytes(55)); + \Drupal::cache('bootstrap')->invalidate('phpstorage_hash'); + } + }