404 not expired for 3 minutes

Hi,

I am referring to this post How to avoid caching 404 - #15 by dev99 and it said 404 pages will expires after 3 minutes. But for my case, it is not the case, below is an example:

https://www.datanumen.com/blogs/wp-content/uploads/2015/11/For-a-Small-business-or-team-Ms-Outlook-can-be-used-for-task-management.jpeg

The response header in DevTools is:

My settings are:

  1. Wordpress site with Cloudflare APO plugin installed.
  2. Cache rule is standard.
  3. Edge TTL is 14 days.
  4. Browser TTL is 5 days.

Thank you.

FYI, Cache-control: max-age=432000 means cache for 5 days, which is what you have set as the Browser Cache TTL.

The page rule you’ve created is overriding the default 3-minute header for 404s.

Are you using Cloudflare APO? Or is this some other plugin?

@macktoy

Yes, I am using Cloudflare APO plugin. Then how to override and set browse TTL for 404 pages to 3 minutes again?

Theoretically, a 404 is a somewhat permanent condition, so I don’t see a problem with keeping that 14 Day Edge Cache TTL.

But if you’ve changed something to stop that 404 from happening, I suggest you try to Purge by URL.

@sdayman

Thank you. The strange thing is that the file does exist:

https://www.datanumen.com/blogs/wp-content/uploads/2015/11/For-a-Small-business-or-team-Ms-Outlook-can-be-used-for-task-management.jpeg

so this 404 seems to be a false positive report.

Purge cache will solve the issue. However, is there an automatic way to do that? Because it seems there will be such fake 404 links from time to time. And purging them manually is also because a daily burden.

Thank you very much.

Well, now it looks like you have a different problem to track down (why your server is sending a 404 for that URL).

@sdayman

Yes, the server returns 404 is an issue to be solved.

Also I wonder if it is possible to set a rule specific for 404 status code, and set the browser TTL back to the default 3 minutes?

Thank you very much.

The only thing I can think of is a Worker that looks at every request to see if the server responds with a 404, then it would tell Cloudflare to Bypass Cache for that request. I’ve not seen anybody do this, so you’d have to craft this yourself.

Alternatively, you could remove the Browser Cache TTL setting from Cloudflare and set cache-control headers in Wordpress (or at the server level). In that case, you could also control the Edge Cache TTL the same way by setting a cdn-cache-control header.

The trick is setting a cache header at the origin when it’s a 404.

I’m not even sure how Cloudflare handles caching of a 404 when there’s a Cache Everything rule set. I suppose they take it as a “Hey, you said cache everything.” But as I said earlier, a 404 should be a somewhat permanent condition, except it’s not in this case.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.