Could CF / R2 interfere with legit traffic?
i know for a fact i will have a big spike in downloads roughly a week from now. i don't get too much traffic yet but it will be about 3000 users downloading the same ~50 files at once. will r2 be okay with this? i don't want cf firewall or some hidden r2 rate limits to kick in and cause real users to not be able to recieve their downloads
7 Replies
Yeah there should be no problem with it. I don't know the size of your files but I would recommend using a custom domain to take advantage of caching
yep it's on a custom domain through r2 and i have rules set up to cache on that subdomain
most files are in the 10-150mb range
would caching be completely impossible if I switched to serving through workers api? been meaning to get some more advanced analytics going but there's no way to use callbacks on say a file download event via r2
You'd have to use the cache API in workers but it would still work. It is the only way to know if know what files have been downloaded.
So to clarify, CF on its own will not cache responses from a worker (let's say test.com/image.png , no query params, just a straight "filepath") if I don't directly use the Cache API, but it will do it for me if I go through the r2 subdomain?
Correct. Workers run in front of the cache so the only way to cache is with the cache API. A custom domain for R2 will use your zone's cache settings
So I would then be manually placing objects in some arbitrary CF cache, and serving them myself from said cache in the worker's responses? Would this be significantly slower than the default caching behavior, or about the same speed?
You can stick the cache responses after you have returned a response to the user so there shouldn't be any significant speed difference