I’m using the following CF features to try and mimic a complete edge experience for most of my site.
Argo Tiered Cache
Cache Reserve
“Cache everything” page rule
This seems to work 99% of the time, but every once in a a while I’ll see Googlebot or different user agent get served a MISS for a url (which should fall under the above category)
I need this to be 100% as a URL from the origin could take a couple seconds to load ( PHP, DB issues I need to resolve)
Is there a way to use a CF worker and the cache api to make sure a URL never gets served with a MISS?
Or perhaps there is another solution Im not thinking of?
Would propagating the cache using a VPN from various locations do the trick?
There are a bunch of factors here to consider, I’ll start with your first post.
There is several limitations and requirements assets must meet for Cache Reserve to be used:
Namely,
Be cacheable, according to Cloudflare’s standard cacheability factors,
Have a freshness time-to-live (TTL) of at least 10 hours (set by any means such as Cache-Control / CDN-Cache-Control origin response headers, Edge Cache TTL, Cache TTL By Status, or Cache Rules),
Have a Content-Length response header.
Origin Range requests are not supported at this time from Cache Reserve.
Vary for Images is currently not compatible with Cache Reserve.
Cache Reserve should be a good fallback for a lot of assets, perhaps some assets are still slipping through other requirements like too short cache TTL, missing Content-Length, or just eventually expiring and needing to be refreshed. If your cache rate is truly 99%, that’s pretty good.
Normal Cache can be quite effective on its own as well, but you need requests flowing to keep it happy. Especially if you are on free plan with low requests, your assets will be evicted sooner rather than later, using a VPN wouldn’t help, you’d fill up a few zone caches for a bit, but if you weren’t getting enough requests to keep your assets in cache to begin with, you’d have the same issue.
Using a Cloudflare Worker with Cache API is a major step back. The Cache API does not use Tiered Cache or Cache Reserve, it merely interacts with the local cache of the colo (cf data center) the Worker is running in.
That worker is entirely a result of ChatGPT’s Hallucinations (I assume also that was GPT 3.5 and not 4). That’s not how you use resolveOverride, and that whole alternative datacenter idea would never work/makes no sense.
In my opinion, you’re spending too much time trying to fix the symptoms of the issue instead of the issue itself. Even with all of the layers of cache in the world, cache is eventually going to expire. That’s the nature of cache.
If you’re using something like WordPress, there are plugins to export your site to static html/css/js that you can then throw onto Cloudflare Pages, which would not require your origin at all and all of your assets would be served from Cloudflare itself:
There’s no way to absolutely guarantee a hit. If you want a “complete edge experience”, you could switch to something like Cloudflare Pages, but that’s only going to work with static html/css/js or supported SSR Frameworks (not php).
It’s close to it yes, I’ve set response headers to a TTL of months in most cases
Im on the Pro plan and this very interesting and makes sense, Im sure the pages are not getting enough hits so this could be the reason for them being evicted.
It’s 4 actually but see your point
I think you sold me here, its not consistent and is a little over my head, had a programmer looks at it a while ago but he was never able to figure it out. Its Joomla 3 with a bunch of custom modifications, Im thinking its SQL related but will need to really look into it
Im curious, 99% of the site is static, its just the user login and backend thats really dynamic. Could this be a solution where I keep the login and admin on in its current state and use the CF pages for everything else?
In the past, you would need to have locations in at least 285 cities that CF operates datacenters in But Cloudflare Tiered Caching Tiered Cache · Cloudflare Cache (CDN) docs should help with that somewhat. If you analyze your CF Tiered Caching analytics and figure out your Tiered cache datacenter locations, you can probably just hit those ones to keep a pre-warm cache.
That isn’t possible as Cloudflare CDN caching is done on a per datacenter basis and there’s over 285 cities and 100 countries where CF has presence in. There are many steps you can take to get closer to that possibility of nearly always being in CF CDN cache like
Cache Everything Page Rule or CF Cache Rule equivalent
Cache Reserve only if your origin asset response returns a content-length header which most gzip/brotli compressed responses from origin servers won’t include - so Cache Reserve ends up making such asset serving infact slower rather than faster
Cloudflare Enterprise plan’s Cache Prefetch which can effectively CDN cache prefetch URLs you tell it to prewarm the CF CDN cache with Prefetch URLs · Cloudflare Fundamentals docs
URL prefetching means that Cloudflare pre-populates the cache with content a visitor is likely to request next. This setting — when combined with additional setup — leads to a higher cache hit rate and thus a faster experience for the user.
If you read my TTFB optimization guide at Improving Time To First Byte (TTFB) With Cloudflare the 3 segments of optimizations, the last being your origin server side optimizations need to be taken care of.
Youre right, the only thing that returns a content length header are png images and fonts, if I add the content length header (via a CF transform rule) to the html, svg, js, css would that work to keep them in the reserve?
Edit does the content length value have to be exact for this to work?
I haven’t tried incorrect/inaccurate content length headers. I don’t think CF Transform rule would work, it would have to come from your origin server. I wouldn’t rely on Cache Reserve anyway, Tiered Cache would be a better option.