Commit 19f7e413 authored by webchick's avatar webchick
Browse files

Issue #2474909 by alexpott, mpdonadio, znerol, catch, Wim Leers, Berdir: Allow...

Issue #2474909 by alexpott, mpdonadio, znerol, catch, Wim Leers, Berdir: Allow Simpletest to use the same APC user cache prefix so that tests can share the classmap and other cache objects
parent 2ba42690
......@@ -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;
}
......
......@@ -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();
......
......@@ -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);
}
}
......@@ -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';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment