My module uses hook_node_view() to add some contents to the node view.
function example_node_view() {
if ($view_mode == 'full' && $node->bundle() == 'example')
// Insert file listing content part
$contents = Class::getContents();
$build['example'] = $contents;
}
Drupal 8 caches the node view by default and only calls hook_node_view() once after each cache rebuild. For this module to function, hook_node_view() should run every time the node is requested. So, I am looking for ways to invalidate node:nid cache tag.
NB: - I am not looking for ways to disable the caching for a development.
public function getContents(){
return [
"#type" = 'table',
"#header' = 'header',
.....
];
Solved by adding the CacheDependency to hook_node_view() as indicated by @4k4
$renderer = \Drupal::service('renderer');
$renderer->addCacheableDependency($build, $node->id());
$content
coming from? Is this from the database or external? How often does this change?