Cache Everything for all domain but force PHP routes to never cache

I’m considering using “Cache Everything” for my whole domain by a single Page Rule.
However, I have a few pages on my site that use PHP and need to avoid being cached.

In that case, is there any problem if I just use php cache-control headers on those pages to avoid cache for the PHP route?
More info here.

Cloudflare docs state we shouldn’t use Cache Everthing for pages like the “login” page. But why can’t we if we then use PHP headers to specify that we don’t want to cache that specific page within the site?

Also, my PHP routes won’t include .php extension. They can be .html or even directories /. So I can’t use the solution proposed in this other issue.

That is a good question and something I suggest you simply try it out.

Generally, sending cache-control: no-store should prevent Cloudflare from caching, however I cant tell how the proxies react with an explicit “cache everything” rule.

Best advice, just try it :slight_smile:

Would there be any downside on implementing this approach?
I can’t seem to find any other post on the internet talking about it. Wonder why…

It could be a bit risky. Should Cloudflare cache it for whatever reason, you will have to purge it manually or wait until it expired as it wont send the request to the origin any longer in the first place.

1 Like

What do you mean?
Why would Cloudflare cache it if I’m telling it not to? Did you ever experienced such miss behaviour before?

Currently I’m testing it as you suggested in a subfolder configured like so:

Cache Level: Cache Everything

So I added a test.php file in /blog/ and added:


header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');

echo date("d-m-Y h:i:s");

Now it displays the correct time every reload and shows cf-cache-status: BYPASS

Then I’d say it should work. Still, test it further before rolling it completely out into production.

1 Like

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