Cache headers are ignored


#1

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.


#2

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


#3

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


#4

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).


#5

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.


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

@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.


#7

@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.


#8

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…


#9

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…


#10

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


#11

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.


#12

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)


#13

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


#14

I am having the same issue.

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

Expectations:

Reality:

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