Drupal has an amazing cache that enables highly granular caching, so that the page can be set up to rebuild only when it needs to. When everything is configured properly, pages load extremely quickly and refresh immediately when content is changed. This is managed by declaring cache dependencies.

Sometimes I end up needing to build pages that might have multiple nodes’ content on them, like say for example some kind of landing page. A simple way I sometimes declare dependencies on a page like this is to put them right in the template. So for example in node--my_landing_page.html.twig I’d add the following:

{{{
  '#cache':  {
    'tags':  [
      'node_list:my_content_type',
    ],
  },
}}}

you could also declare dependencies on specific node or block ids if you’re using those in your template:

{{{
  '#cache':  {
    'tags':  [
      'node:123',
      'block_content:12',
    ],
  },
}}}

or you might want to declare cache context like url args:

{{{
  '#cache':  {
    'tags':  [
      'node_list:my_content_type',
    ],
    'contexts': [
      'url.query_args',
    ],
  },
}}}

The syntax looks a bit weird with the triple backets, but it’s just a twig array enclosed in {}, surrounded by {{}}.

Just one of those features I don’t see documented much, so thought I’d share.