ApcuBackendFactory.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Drupal\Core\Cache;
  3. use Drupal\Core\Site\Settings;
  4. class ApcuBackendFactory implements CacheFactoryInterface {
  5. /**
  6. * The site prefix string.
  7. *
  8. * @var string
  9. */
  10. protected $sitePrefix;
  11. /**
  12. * The cache tags checksum provider.
  13. *
  14. * @var \Drupal\Core\Cache\CacheTagsChecksumInterface
  15. */
  16. protected $checksumProvider;
  17. /**
  18. * The APCU backend class to use.
  19. *
  20. * @var string
  21. */
  22. protected $backendClass;
  23. /**
  24. * Constructs an ApcuBackendFactory object.
  25. *
  26. * @param string $root
  27. * The app root.
  28. * @param string $site_path
  29. * The site path.
  30. * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
  31. * The cache tags checksum provider.
  32. */
  33. public function __construct($root, $site_path, CacheTagsChecksumInterface $checksum_provider) {
  34. $this->sitePrefix = Settings::getApcuPrefix('apcu_backend', $root, $site_path);
  35. $this->checksumProvider = $checksum_provider;
  36. if (version_compare(phpversion('apcu'), '5.0.0', '>=')) {
  37. $this->backendClass = 'Drupal\Core\Cache\ApcuBackend';
  38. }
  39. else {
  40. $this->backendClass = 'Drupal\Core\Cache\Apcu4Backend';
  41. }
  42. }
  43. /**
  44. * Gets ApcuBackend for the specified cache bin.
  45. *
  46. * @param $bin
  47. * The cache bin for which the object is created.
  48. *
  49. * @return \Drupal\Core\Cache\ApcuBackend
  50. * The cache backend object for the specified cache bin.
  51. */
  52. public function get($bin) {
  53. return new $this->backendClass($bin, $this->sitePrefix, $this->checksumProvider);
  54. }
  55. }