UpdateCacheBackendFactory.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Drupal\Core\Update;
  3. use Drupal\Core\Cache\CacheFactoryInterface;
  4. /**
  5. * Cache factory implementation for use during Drupal database updates.
  6. *
  7. * Decorates the regular runtime cache_factory service so that caches use
  8. * \Drupal\Core\Update\UpdateBackend.
  9. *
  10. * @see \Drupal\Core\Update\UpdateServiceProvider::register()
  11. */
  12. class UpdateCacheBackendFactory implements CacheFactoryInterface {
  13. /**
  14. * The regular runtime cache_factory service.
  15. *
  16. * @var \Drupal\Core\Cache\CacheFactoryInterface
  17. */
  18. protected $cacheFactory;
  19. /**
  20. * Instantiated update cache bins.
  21. *
  22. * @var \Drupal\Core\Update\UpdateBackend[]
  23. */
  24. protected $bins = [];
  25. /**
  26. * UpdateCacheBackendFactory constructor.
  27. *
  28. * @param \Drupal\Core\Cache\CacheFactoryInterface $cache_factory
  29. * The regular runtime cache_factory service.
  30. */
  31. public function __construct(CacheFactoryInterface $cache_factory) {
  32. $this->cacheFactory = $cache_factory;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function get($bin) {
  38. if (!isset($this->bins[$bin])) {
  39. $this->bins[$bin] = new UpdateBackend($this->cacheFactory->get($bin), $bin);
  40. }
  41. return $this->bins[$bin];
  42. }
  43. }