How to purge cache for workers.dev?
I have a worker that is currently under development and only available via
*.workers.dev, not connected to a domain.
I am trying to purge cached content for it but have not been successful. The worker makes basic fetch() calls to origin that (seem) to get cached.
There is nothing in the Cloudflare Dashboard that I could find (only the cache purge for domains which this worker is not).
I tried the purge cache API with both the *.workers.dev hostname and the origin URL as below but no success.
workers.dev host:
origin URL of a specific file:
Both requests return success: true but the file stays cached in its "old" version.
There is a small chance I have another issue than caching (e.g. getting the wrong file version from origin) but I am not sure and wanted to understand how I can purge the cache for workers.dev only deployments.
Thanks!
Alex3 Replies
FYI in the worker code I am making fetch() calls like this that are the ones getting cached:
(actual code is a bit more involved, this is just an illustrative example)
Workers.dev doesn't sit behind the CDN cache, so yeah that purge call won't be useful for ya. The cacheEverything (https://developers.cloudflare.com/workers/runtime-apis/cache/) config is what's doing ya in.
You could force no-caching by doing something like this:
Or, if you tack on a dummy query param that should also do the trick
Thanks. It's a bit confusing, and I have a hard time finding any clear documentation.
A few more observations:
1. I do see responses headers like
cf-cache-status: HIT in the responses from workers.dev, these are not present in the origin responses, so I am assuming there must be caching going on at the Cloudflare level. For just *.workers.dev.
2. Also the practical fact that files were cached that had newer versions on the origin.
3. After my post I looked into disabling caching entirely (as you also suggested) and found https://developers.cloudflare.com/workers/examples/cache-using-fetch/#using-the-http-cache-api . I set cache: 'no-cache' and removed the cacheEverything on the fetch() call and that seems to work, as newer content started being served, but I am not quite sure. The responses still include cf-cache-status: HIT. And I would love to keep caching enable, just have a way to purge caches when necessary (I have triggers where I could automate it).
4. Side note: I noticed workers.dev does not have a zone id and there is a different zone id for each domain. I happened to pick one from some other existing domain on the account (unrelated to my worker) for my API calls. But I now realize that this could never had any effect since the worker is not in that zone.
Update:
Regarding 3 - disabling the cache: I originally made a mistake there. Also changed it to cache: 'no-store' which seems to be stronger (avoid cache all together).
This seems to work better now in avoiding the cache. Which seems a good enough solution for now.
A colleague also confirmed that there is no apparently no way to purge the fetch() cache.