Skip to main content
How to make a route's response Un-cacheable

There can be scenario's where you might want some custom pages or paths to not be cached. There is a better way of doing it now :

 

Previously

  • In a controller 
    • \Drupal::service('page_cache_kill_switch')->trigger();

 

Better way

  • In a routing file *.routing.yml
    • some.route:
        path: '/some/path'
        defaults:
          _controller: '\Drupal\Some\Controller::response()'
        options:
          no_cache: TRUE

Published on