Cache headers are ignored


Does anybody else has this problem?

If an image is missing i return this headers :
header("HTTP/1.1 404 Not Found"); header('Expires: -1'); header('Pragma: no-cache'); header('Cache-Control: no-cache');

In documentation Cloudflare says it shoud not cache this but it does. Anybody has any idee if i am doing something wrong ?

I have a rule that sets EDGE Cache TTL to 14 days. Also if this rule is active the 302 are not cached anymore.

1 Like


It will cache 404’s if you have selected Cache level: Cache everything.



It is not selected Cache level: Cache everything but it still caches .



Hi @ciprian,

Note that if you force an Edge Cache TTL to 14 days and use “Cache Everything”, then for HTTP 200 & 301 responses codes we’ll force that Edge Cache TTL.

For other response codes such as 302, 303, 403, 404 we’ll cache those for 5 minutes. That’s what I think your problem is here.

What you need to do here is change your page rule to “Respect All Existing Headers” for Edge Cache TTL and then have your origin send 14 day TTLs when you want the response to be cached (e.g. HTTP 200s), and “no-cache” when you don’t want caching (e.g. HTTP 404s).



So, after discussing with support and some testing i reached the following conclusion.

If i create a page rule with only Edge Cache TTL active then, all 404’s will be cached for an unknown period of time, all 302 will not be cached at all. For the 302 to be cached i will have to activate the “cache everything” option.

I don’t know if you plan to change this but how it should work, in my opinion , should be like this :

If i set Edge Cache TTL then all cacheable urls that don’t have the “no-cache” header should be cached , and of course, ignoring the TTL from headers.
If i also set the “Cache Everything” then all urls should be cached ignoring the headers.

1 Like

Cache-Control headers from origin not being respected for POST requests

@ciprian thanks for the feedback on that. For the record 302 and 303 responses would be cached for 5 minutes with “Cache Everything” and an “Edge Cache TTL” hard coded on the page rule.

Right now for the finest grained control of caching, you should set the Edge Cache TTL to “Respect All Existing Headers” and you can control what is cached and for how long using the origin cache headers.

1 Like


@simon i don’t think that Edge Cache TTL has an option “Respect ALL Existing Headers” , i found that option only at Browser Cache Expiration but not in the page rule setting, just on the global setting.

1 Like


As @ciprian pointed out, this option indeed seems not to exist. The headers returned by the origin server seem to be ignored and CloudFlare uses the TTL of the “global setting” defaulting to 4 hours…



It seems this is a bug in the Management GUI.

When using the API to set a Edge Cache TTL of ‘0’ seconds, it is accepted.
When then browsing to the Management GUI, I see the label:

  • “Edge Cache TTL: Respect Existing Headers”

So it can be configured, but not using the GUI…



Unfortunately, setting the Edge Cache TTL to 0 seems to disable it, only got MISS results now :frowning:



My mistake - the Edge Cache TTL setting of “Respect All Existing Headers” is only available on the Enterprise plan.

What you should be able to do in this case is simply removed the Edge Cache TTL setting entirely from the relevant page rule - we will then obey the origin cache headers.

1 Like


If the 404 response does not include caching headers what will CloudFlare do?
We are using CloudFront and origin server (since only CloudFront supports multiple origins by path)



Absent an explicit cache header we will cache the response for 5 minutes:



I am having the same issue.

It seems “Cache Level: Cache Everything” + “Origin Cache Control: on” as page rule does not work as expected.



  • all pages are being cached independently of the the cache-control headers on origin


Hi I am having the same issue.

My goal is to avoid Cloudflare from caching 404 static assets during rolling update deployment. I am NOT using Cache Everything and have Cache-Control set to no-cache in my nginx if 404 happen on my static assets. But still Cloudflare does not respect my Cache-Control header. I understand be default Cloudflare will cache 404 for 5 mins. But it will also respect Cache-Control header by reading the following article.

Is there any workaround for this issue? I still want the benefit of caching static assets. But just not caching 404 for 5 minutes.



@hokichaio First thing to do would be to ensure your origin is actually returning no-cache when a 404 is returned. Try cURL like this:

curl -svo /dev/null --connect-to ::

Replace the domain / url with one that will trigger the behaviour you have configured for 404s. Replace the IP address with your origin server IP address or hostname.