Code snippet that can use to disable cache for a specific page in drupal 8.
Disable cache for a specific content type
Example:
<?php
use Drupal\node\NodeInterface;
/**
* @param array $build
* @param NodeInterface $node
* @param $display
* @param $view_mode
*/
function mymodule_node_view(array &$build, NodeInterface $node, $display, $view_mode) {
$type = $node->getType();
if ($type == 'article') {
$build['#cache']['max-age'] = 0;
\Drupal::service('page_cache_kill_switch')->trigger();
}
}
Add 'no_cache' route option
Example:
In a route definition (in a *.routing.yml
file):
mymodule.route:
path: '/some/path'
defaults:
_controller: '\Drupal\Some\Controller::response()'
options:
no_cache: TRUE