Don't cache 404 (need to instantly reflect a newly added file)

What is the name of the domain?

https://mediacache.whosum.com

What is the issue you’re encountering

R2 is my origin server for media files. I follow a pattern of: (a) try optimistically to hit the CDN URL, (b) set “onerror” to javascript that posts the media to the R2 if it wasn’t there, and (c) now anticipate a 200 at the URL. However, a Page Rule that results in use of the CDN also caches the 404. Can I use a CDN for my pattern?

You can create a Cache Rules not to cache 404.

Thanks! I guess there’s some interplay between Page rules and Cache rules, right? Does this seem reasonable for my use case above?

Page Rule:
https://mydomain.com/*
Browser Cache TTL: a day, Cache Level: Cache Everything, Edge Cache TTL: a day

Cache Rule:
If custom filter (hostname = mydomain.com) then eligible for cache “Use cache-control header if present, use default Cloudflare caching behavior if not”, Status Code TTL code 404 No Cache.

Thanks again!

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