diff -u b/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php b/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php --- b/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php @@ -17,45 +17,48 @@ use ContainerAwareTrait; /** - * The service name for the consistent backend. + * The service name of the consistent backend factory. * * @var string */ - protected $consistentService; + protected $consistentServiceName; /** - * The service name for the fast backend. + * The service name of the fast backend factory. * * @var string */ - protected $fastService; + protected $fastServiceName; /** * Constructs ChainedFastBackendFactory object. * - * @param \Drupal\Core\Site\Settings $settings - * The settings object. + * @param \Drupal\Core\Site\Settings|NULL $settings + * (optional) The settings object. + * @param string|NULL $consistent_service_name + * (optional) The service name of the consistent backend factory. Defaults + * to: + * - $settings->get('cache')['default'] (if specified) + * - 'cache.backend.database' (if the above isn't specified) + * @param string|NULL $fast_service_name + * (optional) The service name of the fast backend factory. Defaults to: + * - 'cache.backend.apcu' (if the PHP process has APCu enabled) + * - NULL (if the PHP process doesn't have APCu enabled) */ - public function __construct(Settings $settings) { - // Allow settings to specify the two backend services to use. - $cache_settings = $settings->get('cache'); - if (isset($cache_settings['chained_fast_cache'])) { - if (!empty($cache_settings['chained_fast_cache']['consistent'])) { - $this->consistentService = $cache_settings['chained_fast_cache']['consistent']; - } - if (!empty($cache_settings['chained_fast_cache']['fast'])) { - $this->fastService = $cache_settings['chained_fast_cache']['fast']; - } + public function __construct(Settings $settings = NULL, $consistent_service_name = NULL, $fast_service_name = NULL) { + // Default the consistent backend to the site's default backend. + if (!isset($consistent_service_name)) { + $cache_settings = isset($settings) ? $settings->get('cache') : array(); + $consistent_service_name = isset($cache_settings['default']) ? $cache_settings['default'] : 'cache.backend.database'; } - // Otherwise, default to database for the consistent backend, and to the - // APCu (if it's available) for the fast backend. - if (!isset($this->consistentService)) { - $this->consistentService = 'cache.backend.database'; - } - if (!isset($this->fastService) && function_exists('apc_fetch')) { - $this->fastService = 'cache.backend.apcu'; + // Default the fast backend to APCu if it's available. + if (!isset($fast_service_name) && function_exists('apc_fetch')) { + $fast_service_name = 'cache.backend.apcu'; } + + $this->consistentServiceName = $consistent_service_name; + $this->fastServiceName = $fast_service_name; } /** @@ -70,15 +73,15 @@ public function get($bin) { // Use the chained backend only if there is a fast backend available; // otherwise, just return the consistent backend directly. - if (isset($this->fastService)) { + if (isset($this->fastServiceName)) { return new ChainedFastBackend( - $this->container->get($this->consistentService)->get($bin), - $this->container->get($this->fastService)->get($bin), + $this->container->get($this->consistentServiceName)->get($bin), + $this->container->get($this->fastServiceName)->get($bin), $bin ); } else { - return $this->container->get($this->consistentService)->get($bin); + return $this->container->get($this->consistentServiceName)->get($bin); } }