Most effective method for clearing the R2 object cache after updating from Pages Function?

Hello, I am using Cloudflare Pages, and I have connected R2 using Pages Function. Could you please help me purge the R2 object cache after updating the file from the Pages Function? Thanks!
8 Replies
Unsmart
Unsmart16mo ago
Not sure what you mean? R2 isnt cached unless you are specifically using the cache api in which case you can use the purge api to purge it
sultan.xh
sultan.xhOP16mo ago
I am using the cache API. Could you please send me an example code for purging the cache via purge API? Also, is it available inside Pages Function?
sultan.xh
sultan.xhOP16mo ago
I have successfully purged the cache using cache API but I am facing a weird issue now. Once the cache is purged for a single file/URL, it does not update the content immediately. If I go to the file URL directly, I only see changes, but once I do that, the main page fails to load the file and shows a CORS error. Also, purge cache works from localhost using proxy server but not from main domian.
pierpaolograssi
pierpaolograssi15mo ago
hello, the documentation does not explain how to specify single urls to be purged. I can't seem to find this information, anyone can point me in the right direction? thanks
Chaika
Chaika15mo ago
If you want to figure out how something is done and you know the dashboard does is, the easiest way to get that information is just opening up dev tools (Ctrl+shift+i) -> Network, and doing that action in the dashboard and respecting the url and the body. The Purge Cached Content API docs above also has the same information, you just need to click on "any" below Body for the various inputs In this case, it's literally just files being an array of strings, like
{"files":["https://chaika.me/test","https://chaika.me/testi"]}
{"files":["https://chaika.me/test","https://chaika.me/testi"]}
In the future, please make your own thread
No description
Chaika
Chaika15mo ago
a bit late, but if you still haven't figured it out: Can you explain more?
Once the cache is purged for a single file/URL, it does not update the content immediately.
Generally this would be browser cache, the CORS error is strange though. Your main page requests an asset from R2? What is the response when the CORS error happens, is it an error response, or just missing the cors headers?
pierpaolograssi
pierpaolograssi15mo ago
thanks for the tip, much appreciated
Want results from more Discord servers?
Add your server