Invalidate node cache so hook_node_view() runs on each node view My module uses hook_node_view() to add some contents to the node view.

function example_node_view() {
  if ($view_mode == 'full' &amp;&amp; $node-&gt;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-&gt;addCacheableDependency($build, $node-&gt;id());
For new content added to $build you have also add the cache metadata.

Example if you add data from a file entity do this:

$renderer = \Drupal::service('renderer');
$renderer-&gt;addCacheableDependency($build, $file);


This adds the cache tag for the file and whenever this file is changed, the cache item of the node which contains information from the file gets invalidated.

If  the added $content is already a render array with cache metadata drupal will merge this. You can check, which cache tags are missing in $content and add them in the class that generates this data.

Reference: https://www.drupal.org/docs/8/api/render-api/cacheability-of-render-arrays

If what the comment in the code suggests you have a list of files, you can add the tag 'file_list'. All entities invalidate the tag [entity-type]_list when creating, changing or deleting an entity. 

Edit:

If you use the standard tools, that is building single entity displays with the view() method and list of entities with Views, then you don't need to take care of cache dependencies, because the render arrays these tools produce contain all necessary cache metadata.