404 cache not clearing

Hi there,

I just spent a whole day trying to work out why 404 cache wasn’t clearing unless visiting the URL directly. Finally 80% through writing a detailed post here asking for help when boom, the caches all start getting marked as EXPIRED and everything loads correctly.

Just to save my sanity, did something happen on CF side that would cause this?

I’m having the exact same problem right now. I’ve narrowed it down to a single header: Origin. Which is why loading the URL directly works but it doesn’t through the website that originally got a 404.

It seems the Edge caches are using Origin as part of its cache key and it’s stuck with a cached 404. Purging caches doesn’t work.

This only started when I introduced a “Cache Everything” and “Edge Cache TTL” page rule so I think there’s something wrong on Cloudflare’s Edge that is delaying cache expiry for 404s, which in their docs, should be 3 minutes by default without any Cache-Control headers from Origin.

I set my Edge TTL to a month, so I’m guessing the 404 will clear in a month… For you (@dshenton) I’m guessing you had a lower TTL so it started working again.

For now, I’m going to explicitly add a Cache-Control: no-cache header, it should work. But this will be a problem for anyone that doesn’t have access to 404 pages (e.g. AWS S3).

Update: Adding a no-cache header to 404s doesn’t work. Cloudflare still HITs its cache and never BYPASSes.

I’ve also noticed Purging cache works for requests without an Origin header but does nothing on requests with Origin (i.e. they still HIT and their age continues to increase).

As expected, turning off Cache Everything solves the issue. But that’s not an ideal solution.

Update: I re-enabled Cache Everything and removed the Edge Cache TTL rule. That also works. So “Edge Cache TTL” seems to be the rule that overrides the 3 minute 404 response caches.

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