1

My Cache-Control header is always set to must-revalidate, no-cache, post-check=0, pre-check=0, private on the front page as well as every other page.

I've gone to configuration>performance and set Page cache maximum age to 5 mins, and I've gone to every view and set time-based caching to 5 mins as well.

There are a lot of articles about what to grep for in modules that might disable caching on a page, but these are all for Drupal 7, and I'm on Drupal 8.

What should I be looking for in my D8 modules that might be killing my caches? If I don't fix this header, CloudFront won't like my pages very much.

EDIT: The poll module was invalidating my caches on pages that were showing poll results, but that didn't turn out to be my main issue. After disabling the poll module, I was still getting must-revalidate, no-cache, post-check=0, pre-check=0, private, but only on my Firefox Developer Edition (with browser caching disabled, though that probably doesn't matter) while all other browsers (including regular Firefox, with or without caching disabled) are returning max-age=300, public as they should. I'm concerned, does this mean users can bypass caching under the right circumstances?

  • Are there any custom modules that you wrote? – cilefen Dec 22 '15 at 19:38
8

In general, this is pretty hard to answer without going into details and knowing what you did with your site. But to give you a few starting points...

  • To ask the obvious, you are testing this as an anonymous user without a session, right?
  • If you do have a session, check what values you have in there and who sets them
  • One thing to grep for is \Drupal::service('page_cache_kill_switch')->trigger();, although it could also be injected, so just look for ->trigger(). That's the equivalent of drupal_page_is_cacheable(FALSE) although are other ways to plug into that too.
  • Typical modules that set this are captcha or poll
  • If all else fails, look at FinishResponseSubscriber, that's the one that adds those headers, specifically look at the request policies that return if a page is cacheable or not (the kill switch is one of those, as is the check for a session)
  • Thanks, Berdir, the poll module was indeed invalidating caches on pages with poll results (using the 'page_cache_kill_switch'), but please see my edit for a concern I have. I'll make a new question for it if someone thinks it's a good idea. – RaisinBranCrunch Dec 22 '15 at 21:27
  • there are always ways to by pass page cache, all you have to do is add ?randomNumber and page cache is out. That was always like that. I'ts improved in D8 because there's also the dynamic page cache module, that only considers query arguments if something tells it that it is relevant for the page. Why that specific browser gets that header I can't say. Blind guess would be a do not track header, which I believe google analytics by default respects and will disable page caching. Or something similar like that. – Berdir Dec 22 '15 at 21:34
  • Also look for modules that are setting cookies. If the browser request header includes a cookie, Drupal will return an uncached page. – Renee Nov 20 '16 at 21:57
0

to solve I used this module http_response_headers. Can solution my bug whith headers http.

Steps:

  1. Install Module
  2. Configuration Response header configuration
  3. Go path: /admin/config/system/response-headers
  4. Add Response header configuration
  5. Configuration the fields.
  6. Save

For example, my case: enter image description here

My Headers is change:

Before:

enter image description here

After:

enter image description here

I hope it helps in something!

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.