How can I prevent a particular page being cached? I have activated the cache on my Drupal 8 site, and of course all pages are cached as expected.

However, I'd like to have a specific page bypass that cache.

In my controller I built the page as follows:

public function myPage() {
  return [
    '#markup' =&gt; time(),
  ];
}


How can I tell Drupal not to cache my page?
For Drupal 7:

Drupal has the function drupal_page_is_cacheable() which can be used to set a page to uncacheable. 

Here is the documentation: https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/drupal_page_is_cacheable/7

For Drupal 8:

// Deny any page caching on the current request.    
\Drupal::service('page_cache_kill_switch')-&gt;trigger();


Then the code is:

public function myPage() {
  \Drupal::service('page_cache_kill_switch')-&gt;trigger();
  return [
    '#markup' =&gt; time(),
  ];
}


As usual, clean your cache once done.