3 namespace Drupal\Core\Cache;
5 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
8 * Passes cache tag events to classes that wish to respond to them.
10 class CacheTagsInvalidator implements CacheTagsInvalidatorInterface {
12 use ContainerAwareTrait;
15 * Holds an array of cache tags invalidators.
17 * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface[]
19 protected $invalidators = [];
24 public function invalidateTags(array $tags) {
25 assert('Drupal\Component\Assertion\Inspector::assertAllStrings($tags)', 'Cache tags must be strings.');
27 // Notify all added cache tags invalidators.
28 foreach ($this->invalidators as $invalidator) {
29 $invalidator->invalidateTags($tags);
32 // Additionally, notify each cache bin if it implements the service.
33 foreach ($this->getInvalidatorCacheBins() as $bin) {
34 $bin->invalidateTags($tags);
39 * Reset statically cached tags in all cache tag checksum services.
41 * This is only used by tests.
43 public function resetChecksums() {
44 foreach ($this->invalidators as $invalidator) {
45 if ($invalidator instanceof CacheTagsChecksumInterface) {
46 $invalidator->reset();
52 * Adds a cache tags invalidator.
54 * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $invalidator
55 * A cache invalidator.
57 public function addInvalidator(CacheTagsInvalidatorInterface $invalidator) {
58 $this->invalidators[] = $invalidator;
62 * Returns all cache bins that need to be notified about invalidations.
64 * @return \Drupal\Core\Cache\CacheTagsInvalidatorInterface[]
65 * An array of cache backend objects that implement the invalidator
66 * interface, keyed by their cache bin.
68 protected function getInvalidatorCacheBins() {
70 foreach ($this->container->getParameter('cache_bins') as $service_id => $bin) {
71 $service = $this->container->get($service_id);
72 if ($service instanceof CacheTagsInvalidatorInterface) {
73 $bins[$bin] = $service;