You are here

class ConfigCacheInvalidator in Sub-pathauto (Sub-path URL Aliases) 8

A subscriber invalidating cache tags when subpathauto config is saved.

Hierarchy

  • class \Drupal\subpathauto\EventSubscriber\ConfigCacheInvalidator implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ConfigCacheInvalidator

1 string reference to 'ConfigCacheInvalidator'
subpathauto.services.yml in ./subpathauto.services.yml
subpathauto.services.yml
1 service uses ConfigCacheInvalidator
subpathauto.config_cache_invalidator in ./subpathauto.services.yml
Drupal\subpathauto\EventSubscriber\ConfigCacheInvalidator

File

src/EventSubscriber/ConfigCacheInvalidator.php, line 13

Namespace

Drupal\subpathauto\EventSubscriber
View source
class ConfigCacheInvalidator implements EventSubscriberInterface {

  /**
   * The cache tags invalidator.
   *
   * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
   */
  protected $cacheTagsInvalidator;

  /**
   * Constructs a SubPathautoSettingsCacheInvalidator object.
   *
   * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
   *   The cache tags invalidator.
   */
  public function __construct(CacheTagsInvalidatorInterface $cache_tags_invalidator) {
    $this->cacheTagsInvalidator = $cache_tags_invalidator;
  }

  /**
   * Invalidate the 'rendered' cache tag whenever the settings are modified.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   *   The Event to process.
   */
  public function onSave(ConfigCrudEvent $event) {

    // Changing the Subpathauto settings means that any cached page might
    // result in a different response, so we need to invalidate them all.
    if ($event
      ->getConfig()
      ->getName() === 'subpathauto.settings') {
      $this->cacheTagsInvalidator
        ->invalidateTags([
        'rendered',
      ]);
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[ConfigEvents::SAVE][] = [
      'onSave',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigCacheInvalidator::$cacheTagsInvalidator protected property The cache tags invalidator.
ConfigCacheInvalidator::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ConfigCacheInvalidator::onSave public function Invalidate the 'rendered' cache tag whenever the settings are modified.
ConfigCacheInvalidator::__construct public function Constructs a SubPathautoSettingsCacheInvalidator object.