3 namespace Drupal\Core\Cache;
5 use Drupal\Core\Site\Settings;
7 class ApcuBackendFactory implements CacheFactoryInterface {
10 * The site prefix string.
14 protected $sitePrefix;
17 * The cache tags checksum provider.
19 * @var \Drupal\Core\Cache\CacheTagsChecksumInterface
21 protected $checksumProvider;
24 * The APCU backend class to use.
28 protected $backendClass;
31 * Constructs an ApcuBackendFactory object.
35 * @param string $site_path
37 * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
38 * The cache tags checksum provider.
40 public function __construct($root, $site_path, CacheTagsChecksumInterface $checksum_provider) {
41 $this->sitePrefix = Settings::getApcuPrefix('apcu_backend', $root, $site_path);
42 $this->checksumProvider = $checksum_provider;
43 if (version_compare(phpversion('apcu'), '5.0.0', '>=')) {
44 $this->backendClass = 'Drupal\Core\Cache\ApcuBackend';
47 $this->backendClass = 'Drupal\Core\Cache\Apcu4Backend';
52 * Gets ApcuBackend for the specified cache bin.
55 * The cache bin for which the object is created.
57 * @return \Drupal\Core\Cache\ApcuBackend
58 * The cache backend object for the specified cache bin.
60 public function get($bin) {
61 return new $this->backendClass($bin, $this->sitePrefix, $this->checksumProvider);