Cache settings - Cloudflare override?

It seems there are multiple places to set cache headings. I’m trying to set up “cache everything” in Cloudflare, but the existing cache settings are overriding things.

So I’m trying to figure out where the current settings are coming from.

Currently (for the homepage only, I’m seeing

Response headers:

cache-control: max-age=0, must-revalidate, no-cache, no-store
cf-cache-status: DYNAMIC
cf-ray: 53660dd1df53cc08-SIN
content-encoding: br
content-type: text/html; charset=utf-8
date: Sat, 16 Nov 2019 02:32:23 GMT
display: orig_site_sol
expect-ct: max-age=604800, report-uri=“
expires: Fri, 15 Nov 2019 02:32:23 GMT
pagespeed: off
pragma: no-cache

While I do have headers set on other pages in my site, I can’t find anywhere in my own scripts a header that sets the expires date to 24 hours ago for the home page.

In Pre VirtualHost Include in WHM, it suggests there should be a 5 minute expires time, but there isn’t:

ExpiresByType text/html “access plus 600 seconds”

I asked my hosting company to try to track down the setting, and they couldn’t find anything relevant. So my next guess is it’s a setting on Cloudflare.

For the home page only (until I get things sorted out), I’ve set a page rule “Cache everything” and “Origin cache control” to “on”. But the headers still appear as above, with a “one day ago” (and sometimes a 1981 date) expires setting.

This is the header I’m setting on the home page, which should give 1 hour in the future, but doesn’t:

header('Expires: '.gmdate(‘D, d M Y H:i:s \G\M\T’, time() + (60 * 60)));

On my local PC, I’m correctly seeing the expires directive as 1 hour after access, not some 1981 date:

  1. Connection: Keep-Alive
  2. Content-Length: 38
  3. Content-Type: text/html; charset=utf-8
  4. Date: Sun, 17 Nov 2019 08:45:25 GMT
  5. Expires: Sun, 17 Nov 2019 09:45:25 GMT
  6. Keep-Alive: timeout=5, max=100
  7. Server: Apache/2.4.39 (Win64) PHP/7.3.5
  8. X-Powered-By: PHP/7.3.5

If anyone can suggest if this might be a Cloudflare setting and where to change that caching directive, that will be a big help.

No-one answered me, but I figured it out.

I was opening a PHP session() on the affected page and this sets a session cookie. This caused all the “no-cache” headers with “expires” in the past. Removing the session() means “cache everything” now works as expected.

1 Like

Good to know everything was sorted out.

FYI, your “cache everything” page rule could have overridden the origin cache headers with the Edge Cache TTL setting.