diff --git a/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php index bbc4e3d01a34bf078d2f2ec2cfaa9cbf2a934fcf..97a201b96dd80698d93efa8b98f75078b01d041a 100644 --- a/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Cache; -use \Drupal\Component\Utility\Crypt; +use Drupal\Core\Site\Settings; class ApcuBackendFactory implements CacheFactoryInterface { @@ -34,7 +34,7 @@ class ApcuBackendFactory implements CacheFactoryInterface { * The cache tags checksum provider. */ public function __construct($root, CacheTagsChecksumInterface $checksum_provider) { - $this->sitePrefix = Crypt::hashBase64($root . '/' . conf_path()); + $this->sitePrefix = Settings::getApcuPrefix('apcu_backend', $root, conf_path()); $this->checksumProvider = $checksum_provider; } diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 557dfd1e9374c7acb9b42fc109b113b14efd49e2..0b73972181b24d7097d745b0f8711c24e0609f7c 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -249,9 +249,8 @@ public static function createFromRequest(Request $request, $class_loader, $envir // loader. if ($class_loader_class == get_class($class_loader) && Settings::get('class_loader_auto_detect', TRUE) - && Settings::get('hash_salt', FALSE) && function_exists('apc_fetch')) { - $prefix = 'drupal.' . hash('sha256', 'drupal.' . Settings::getHashSalt()); + $prefix = Settings::getApcuPrefix('class_loader', $core_root); $apc_loader = new \Symfony\Component\ClassLoader\ApcClassLoader($prefix, $class_loader); $class_loader->unregister(); $apc_loader->register(); diff --git a/core/lib/Drupal/Core/Site/Settings.php b/core/lib/Drupal/Core/Site/Settings.php index a48946a22ca16ff7544923ea2965a61bd90440a8..18f55ff96b09f554aa9c1ed64faefc064495651c 100644 --- a/core/lib/Drupal/Core/Site/Settings.php +++ b/core/lib/Drupal/Core/Site/Settings.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Site; +use Drupal\Component\Utility\Crypt; use Drupal\Core\Database\Database; /** @@ -148,4 +149,31 @@ public static function getHashSalt() { return $hash_salt; } + /** + * Generates a prefix for APC user cache keys. + * + * A standardized prefix is useful to allow visual inspection of an APC user + * cache. By default, this method will produce a unique prefix per site using + * the hash salt. If the setting 'apcu_ensure_unique_prefix' is set to FALSE + * then if the caller does not provide a $site_path only the Drupal root will + * be used. This allows WebTestBase to use the same prefix ensuring that the + * number of APC items created during a full test run is kept to a minimum. + * Additionally, if a multi site implementation does not use site specific + * module directories setting apcu_ensure_unique_prefix would allow the sites + * to share APC cache items. + * + * @param $identifier + * An identifier for the prefix. For example, 'class_loader' or + * 'cache_backend'. + * + * @return string + * The prefix for APC user cache keys. + */ + public static function getApcuPrefix($identifier, $root, $site_path = '') { + if (static::get('apcu_ensure_unique_prefix', TRUE)) { + return 'drupal.' . $identifier . '.' . hash_hmac('sha256', $identifier, static::get('hash_salt', $root . '/' . $site_path)); + } + return 'drupal.' . $identifier . '.' . Crypt::hashBase64($root . '/' . $site_path); + } + } diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 29874118a9b62fff0aa2e6db426c267693f1d80d..c43d57727050819687cbe9d63d0af1d7f0fede1c 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -834,6 +834,10 @@ protected function setUp() { 'value' => $this->originalProfile, 'required' => TRUE, ); + $settings['settings']['apcu_ensure_unique_prefix'] = (object) array( + 'value' => FALSE, + 'required' => TRUE, + ); $this->writeSettings($settings); // Allow for test-specific overrides. $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php';