0

In Drupal 7, I found a way to reset cache on a specific page with:

$url = url('<front>',  array('absolute' => TRUE));
cache_clear_all($url, 'cache_page');

What is the equivalent way in Drupal 9?

4

1 Answer 1

2

Solved it like this:

$url = Url::fromUserInput($custom_url);
  if ($url instanceof UrlInterface) {
    if ($url->isRouted()) {
      $nid = $url->getRouteParameters()['node'];
      /** @var \Drupal\node\Entity\Node $node */
      $node = Node::load($nid);
      if ($node instanceof NodeInterface) {
        $tags = $node->getCacheTags();
        \Drupal::service('cache_tags.invalidator')->invalidateTags($tags);
      }
    }
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.