Content-type: text/html is returning cf-cache-status: MISS even with page rules setup

I have a wordpress website that I want to cache the HTML for. I have setup some page rules that i want to use to cache the HTML for the entire website. So if a user visits The HTML of this will be cached and served instead of having to make PHP render that HTML.

Here is the configuration I have set in the Cloudflare admin panel.

Here are the headers i get back in the response. I have tried multiple browsers, some logged into wordpress and others logged out. Nothing seems to make this return a cache hit. All other static assets like css, js and images are caching as expected.

cache-control: no-store, no-cache, must-revalidate
cf-cache-status: MISS
cf-ray: 4f4347dc2a5aa6a5-DUB
content-encoding: br
content-type: text/html; charset=UTF-8
date: Wed, 10 Jul 2019 14:38:19 GMT
expect-ct: max-age=604800, report-uri=“
expires: Thu, 19 Nov 1981 08:52:00 GMT
pragma: no-cache
server: Cloudflare
status: 200
vary: Accept-Encoding
x-powered-by: PHP/7.0.33

That says no-cache, Your page must still send the proper cache-control header, for example:

public, max-age:1260000

If you can’t actually change this header, setting the rule “edge cache TTL” will work (but then you need to be wary about dynamic content being cached if you have dynamic content).

Your page rule has “Browser cache TTL”, which won’t work for HTML since the browsers themselves will never cache HTML.

Dynamic aspects are ajax powered so I am happy that all of these things are safe from html caching issues. I have a rule in the index.php file that will take the url and fetch if from a redis cache if it exists. I cant implement a reverse proxy right now but if Cloudflare can do the same thing i am currently doing with PHP it would be a huge performance gain.

If i configure the PHP to return headers with the page itself, Cloudflare will honor these? For example, if i set the home page and any pages that refresh often to have an age of 6 hours and then more static post pages to live for a month, Cloudflare will read those HTTP headers and cache that HTML response accordingly without me having to configure anything else? If someone visits in future, Cloudflare wont even call my web server if that HTML lives in the cache?

I have a couple of sites running full page cache on html, dynamic content is loaded by ajax, it makes the sites really fast. (The ajax call gets / sets cookies)

I remove the headers ‘expires’ and ‘pragma’ etc on the server then set Cloudflare to respect existing headers.

I don’t use Browser cache TTL in the rule, I send Cache-Control max-age from the server.
It’s probably different depending on what your server sends, but I am careful to only do that on pages I want cached.

Also I remove the ‘set-cookie’ on those pages, you really dont want problems there, but when I was first setting this up Cloudflare refused to cache the html when the server set a cookie but you should check that.
I assume Cloudflare will not cache the ‘set-cookie’ header but I really dont know how Cloudflare goes about caching pages that had a set-cookie header from the server.

This topic was automatically closed after 30 days. New replies are no longer allowed.