Block caching examples
Goran Nikolovski, Feb 7, 2019
https://gorannikolovski.com/blog/block-caching-examples
Drupal 8 : How To Avoid Block Caching
#! code, Feb 11, 2018
https://www.hashbangcode.com/article/drupal-8-how-avoid-block-caching
$build = [
'#cache' => [
'max-age' => 0,
];
use Drupal\Core\Cache\UncacheableDependencyTrait;
/**
* Example Block.
*
* @Block(
* id = "example_block",
* admin_label = @Translation("Example"),
* )
*/
class ExampleBlock extends BlockBase {
use UncacheableDependencyTrait;
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return Cache::mergeContexts(parent::getCacheContexts(), array('route'));
}