Change record status: 
Project: 
Introduced in branch: 
11.2.x
Introduced in version: 
11.2.0
Description: 

Block plugins can now indicate that they are very not worth caching by implementing \Drupal\Core\Cache\CacheOptionalInterface.

In some cases, loading a cached version of a rendered block may be more expensive than just rendering the block, especially if those blocks also have many variations.

A good example is the language switcher block, that varies for every URL.

This is different from setting max-age 0, which means that the content of a block must not be cached at all. CacheOptionalInterface only applies to to separate block cache, the block may still be cached by the dynamic and anymous page caches for example.

A different system that uses CacheOptionalInterface are access policies, which are often also fast and do not require persistent caching.

Related issues

Support CacheOptionalInterface in BlockViewBuilder, use it in language switcher block to prevent max-age 0 bubbling
Add CacheOptionalInterface to more blocks

Impacts: 
Module developers