class CacheTagsInvalidator
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Cache/CacheTagsInvalidator.php \Drupal\Core\Cache\CacheTagsInvalidator
- 10 core/lib/Drupal/Core/Cache/CacheTagsInvalidator.php \Drupal\Core\Cache\CacheTagsInvalidator
- 11.x core/lib/Drupal/Core/Cache/CacheTagsInvalidator.php \Drupal\Core\Cache\CacheTagsInvalidator
Passes cache tag events to classes that wish to respond to them.
Hierarchy
- class \Drupal\Core\Cache\CacheTagsInvalidator implements \Drupal\Core\Cache\CacheTagsInvalidatorInterface uses \Symfony\Component\DependencyInjection\ContainerAwareTrait
Expanded class hierarchy of CacheTagsInvalidator
1 file declares its use of CacheTagsInvalidator
- CacheTagsInvalidatorTest.php in core/
tests/ Drupal/ Tests/ Core/ Cache/ CacheTagsInvalidatorTest.php
1 string reference to 'CacheTagsInvalidator'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses CacheTagsInvalidator
File
-
core/
lib/ Drupal/ Core/ Cache/ CacheTagsInvalidator.php, line 11
Namespace
Drupal\Core\CacheView source
class CacheTagsInvalidator implements CacheTagsInvalidatorInterface {
use ContainerAwareTrait;
/**
* Holds an array of cache tags invalidators.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface[]
*/
protected $invalidators = [];
/**
* {@inheritdoc}
*/
public function invalidateTags(array $tags) {
assert(Inspector::assertAllStrings($tags), 'Cache tags must be strings.');
// Notify all added cache tags invalidators.
foreach ($this->invalidators as $invalidator) {
$invalidator->invalidateTags($tags);
}
// Additionally, notify each cache bin if it implements the service.
foreach ($this->getInvalidatorCacheBins() as $bin) {
$bin->invalidateTags($tags);
}
}
/**
* Reset statically cached tags in all cache tag checksum services.
*
* This is only used by tests.
*/
public function resetChecksums() {
foreach ($this->invalidators as $invalidator) {
if ($invalidator instanceof CacheTagsChecksumInterface) {
$invalidator->reset();
}
}
}
/**
* Adds a cache tags invalidator.
*
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $invalidator
* A cache invalidator.
*/
public function addInvalidator(CacheTagsInvalidatorInterface $invalidator) {
$this->invalidators[] = $invalidator;
}
/**
* Returns all cache bins that need to be notified about invalidations.
*
* @return \Drupal\Core\Cache\CacheTagsInvalidatorInterface[]
* An array of cache backend objects that implement the invalidator
* interface, keyed by their cache bin.
*/
protected function getInvalidatorCacheBins() {
$bins = [];
foreach ($this->container
->getParameter('cache_bins') as $service_id => $bin) {
$service = $this->container
->get($service_id);
if ($service instanceof CacheTagsInvalidatorInterface) {
$bins[$bin] = $service;
}
}
return $bins;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
CacheTagsInvalidator::$invalidators | protected | property | Holds an array of cache tags invalidators. | |
CacheTagsInvalidator::addInvalidator | public | function | Adds a cache tags invalidator. | |
CacheTagsInvalidator::getInvalidatorCacheBins | protected | function | Returns all cache bins that need to be notified about invalidations. | |
CacheTagsInvalidator::invalidateTags | public | function | Marks cache items with any of the specified tags as invalid. | Overrides CacheTagsInvalidatorInterface::invalidateTags |
CacheTagsInvalidator::resetChecksums | public | function | Reset statically cached tags in all cache tag checksum services. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.