A new module was added to Drupal 8, the Dynamic Page Cache. Like the Page Cache module caches static pages for anonymous users, the Dynamic Page Cache caches dynamic pages for all users. It is able to cache just the parts of the page that are not unique to the current user, and still render the rest dynamically.
See https://www.drupal.org/documentation/modules/dynamic_page_cache for more information. For those coming from Drupal 7: this is essentially https://www.drupal.org/project/authcache in core
.
How to get it
New installs of Drupal 8 (commit 5e8523ecb95f1530e80ea2d9929135ef9b3f8733 or later) will have this module installed automatically (in the Standard or Minimal install profile). Existing installs can opt in by manually enabling the module. Existing Drupal 8 install profiles/distributions can opt in by updating their .info.yml file.
Contrib modules whose tests are failing
If you maintain a D8 contrib module whose tests are failing since this commit, then that's because your module's rendered output (controllers, blocks, entities, field formatters, responses …) do not yet specify cacheability metadata. Without the cacheability metadata to match your rendered output, Drupal cannot know when to invalidate cached output, or by what contexts to vary it.
See:
- https://www.drupal.org/developing/api/8/render/arrays/cacheability
- https://www.drupal.org/developing/api/8/cache/tags
- https://www.drupal.org/developing/api/8/cache/contexts
- https://www.drupal.org/developing/api/8/cache/max-age
- Only as an absolute last resort, you should use the
'no_cache'route option to mark a route's responses as uncacheable. It's much better to setmax-age=0on the dynamically rendered content that you don't want to be cached, that at least allows non-dynamic/cacheable parts of the page (e.g. some blocks) to be cached.