Interestingly, by default, there is no way a Twig template can inform Drupal about its caching requirements. Obviously, there are some templates (e.g. for a news box paragraph etc.) that you'd like to refresh quite often - and other templates that you don't need to refresh that much. Some templates might need to be refresh if some other node is changing, others might need to change depending on whether a specific cookie is set or not. Drupal's sophisticated caching system fortunately supports all those use cases, but, as stated above, there is no way to make use of that easily from Twig.
With DrupalX, you can now use the new "cache" statement in Twig to define certain caching requirements.
maxage
By using cache maxage you can define the maximum age as a caching dependency:
{% cache maxage(60) %}
Current time: {{ "now" | date("H:i:s") }}
In this simple example, you'll find that the template is refreshed every 60 seconds. If you refresh the page more often in your browser, the displayed seconds won't change. Please note, however, that you don't have all caches disabled anyway for development (development.services.yml) for this to work. If you use "cache maxage(0)", it tells Drupal to refresh that template for every page call.
Ok, fine, but there's one caveat, though: If you are using such a cache statement e.g. for a paragraph template, by default Drupal doesn't bubble this information up to the whole page. What does that mean? Well, your paragraph might get a refresh quite happily every 60 seconds if it was accessed, but: Drupal has decided to cache the whole page much longer, so your different paragraph settings are never considered. The underlying bug is discussed in Drupal issue 235009. You'll find patches there which are currently required for this DrupalX feature to work properly. We hope that this won't be necessary in the future anymore.