summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2015-04-29 22:09:14 (GMT)
committerwebchick2015-04-29 22:09:14 (GMT)
commit19f7e4132ef9b7bd2cf188c5173cf7021460e0f7 (patch)
tree79453feef8bf32a9dcd300d927bb3539497c8f40
parent2ba4269034b69fda538eb80e0c4dcc71d50b9a1b (diff)
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
-rw-r--r--core/lib/Drupal/Core/Cache/ApcuBackendFactory.php4
-rw-r--r--core/lib/Drupal/Core/DrupalKernel.php3
-rw-r--r--core/lib/Drupal/Core/Site/Settings.php28
-rw-r--r--core/modules/simpletest/src/WebTestBase.php4
4 files changed, 35 insertions, 4 deletions
diff --git a/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php
index bbc4e3d..97a201b 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 557dfd1..0b73972 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -249,9 +249,8 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
// 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 a48946a..18f55ff 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 @@ final class Settings {
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 2987411..c43d577 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -834,6 +834,10 @@ abstract class WebTestBase extends TestBase {
'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';