Confused about caching

Hey im new here, i have custom domain, url from this custom domain pointing to worker, this worker should on first request cache this url into cloudflare and never invoke again until i purge this url. is this possible? if not, what is best practice most close to what i want? thank you! 🙏
10 Replies
Cyb3r-Jak3
Cyb3r-Jak37mo ago
Workers run before cache. So you need to use the cache API in order to save on time. Keep in mind that cache is per DC and can be evicted.
Patie
Patie7mo ago
https://developers.cloudflare.com/workers/learning/how-the-cache-works/ "Cloudflare Workers can run before and after the cache but can also be utilized to modify assets once they are returned from the cache" this is not true?
Cyb3r-Jak3
Cyb3r-Jak37mo ago
Before cache is because they do things before retreiving from cache. They run after because you can see something from cache then edit it.
Patie
Patie7mo ago
hm pitty, so only possible way is use cache API in this case, but cache API is "edge" or not? in other words it will be fast in whole world similar like cloudflare edge case (or workers) its as close as possible to all visitors?
Cyb3r-Jak3
Cyb3r-Jak37mo ago
It is edge so when your worker adds something to cache it will be cached in that location but a user on the otherside of the world won't hit that cache
Patie
Patie7mo ago
hm but it also located in otherside of world? and when it will be hited by first visitor in otherside of world it will be then hited from cache by every visitor in otherside of world? thank you
Cyb3r-Jak3
Cyb3r-Jak37mo ago
Cache is per DC so if a bunch of users hit the same DC then they will hit the cache
Patie
Patie7mo ago
last question - its possible programatically purge this cache (writed by API) in all DCs? Business plan*
Cyb3r-Jak3
Cyb3r-Jak37mo ago
Yes. The purging cache options will clear the cache API globally.
Patie
Patie7mo ago
thank you