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?
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?
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);
}
}
}