3

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:

http://dev-mysite.pantheonsite.io/:html

(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 Nov 3 '16 at 23:38
  • I have confirmed with Pantheon that Varnish is not caching the pages. – LittleCoding Nov 3 '16 at 23:46
7

(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? – LittleCoding Nov 4 '16 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 Nov 4 '16 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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