I have a form submit function that is meant to invalidate the cache of every node if a specific field is altered. Here's how I'm attempting it.
$config = $this->configFactory
->getEditable('my_config.settings')
->get();
if ($form_state->getValue('global')['header_button'] != $config['global']['header_button']){
// Header Button Changed
\Drupal\Core\Cache\Cache::invalidateTags(['node_list']);
}
From what I've researched I assumed \Drupal\Core\Cache\Cache::invalidateTags(['node_list']);
would invalidate the cache on every node, but the changes to the nodes are not appearing to anonymous users. Not sure if it matters but the change that is made affects what is rendered in region--header.html.twig
rather than node.html.twig
.
I've looked at How do I invalidate the cache of an entity? but the answers there did not work.
\Drupal\Core\Cache\Cache::invalidateTags(['node']);
, but it's a sledgehammer solution and the performance on your site will take a hit, particularly if you have a lot of nodes.