I am having an issue with my whole page's HTML being cached. This is getting in the way of some dynamic block content that is based off of a user preference value (both authenticated and anonymous users).

I have located the cache entry in the cache_render table of the DB and it has a CID of:


(this would be the entry for the front page) I do have the block that builds this dynamic content configured with cache settings:

[#cache]['contexts'] = ['session', 'user'];
[#cache]['max-age'] = 0;

I am only having this caching issue when code is push to the Pantheon servers, local development environments with default cache config settings do not have this issue.

  • Apparently Pantheon, uses Varnish cache which is probably caching the entire page.
    – No Sssweat
    Commented Nov 3, 2016 at 23:38
  • I have confirmed with Pantheon that Varnish is not caching the pages. Commented Nov 3, 2016 at 23:46

1 Answer 1


(Anyonymous) Page cache can not be controlled by max-age or contexts. You need to call \Drupal::service('page_cache_kill_switch')->trigger(); to prevent that kind of caching.

However, if it is a block that is displayed on all pages, then that becomes pretty pointless to even try and you could uninstall the page_cache module completely.

  • Where would I need to use the page_cache_kill_switch service? in the block as it is built? preprocess alter? Commented Nov 4, 2016 at 0:43
  • Doesn't matter where exactly as long as it is called on every request. The block should work if you disabled caching of the block with max-age 0. Another thing to consider to not affect performance of the site would be to move the dynamic part of that block to another request, that you trigger with JS.
    – Berdir
    Commented Nov 4, 2016 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.