ApcuBackendFactory.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. $this->backendClass = 'Drupal\Core\Cache\ApcuBackend';
  37. }
  38. /**
  39. * Gets ApcuBackend for the specified cache bin.
  40. *
  41. * @param $bin
  42. * The cache bin for which the object is created.
  43. *
  44. * @return \Drupal\Core\Cache\ApcuBackend
  45. * The cache backend object for the specified cache bin.
  46. */
  47. public function get($bin) {
  48. return new $this->backendClass($bin, $this->sitePrefix, $this->checksumProvider);
  49. }
  50. }