Cache Api delete help

Hi, I am wondering if someone can help me with something, which I might be misunderstanding, related to deleting from cache using the caches.default.delete() via a worker.

If I make a request, from a machine in the UK, to my API endpoint https://api.{mydomain}.com/users/User123?somequerystring I am successfully getting the response into caching just based on Page Rules (no workers involved at this point).

If I then make a request, from a machine in Portugal, to my API endpoint https://api.{mydomain}.com/users/User124?someotherquerystring I am also successfully getting the response into caching just based on Page Rules (no workers involved at this point).

If I then make a call, from my machine in the UK, to a worker which caches.default.delete(‘https://api.{mydomain}.com/users/User123?somequerystring’) it successfully deletes the entry from caching.

The same happens if I make a call, from my machine in Portugal, to a worker which caches.default.delete(‘https://api.{mydomain}.com/users/User124?someotherquerystring’) it successfully deletes the entry from caching.

Now, when I instead made the first call with the machine in Portugal and the second with the machine in the UK, both were unsuccessful - no match, and so, no successful delete.

Is there a way this can be achieved? I mean, would I be able to call a worker from a machine in, let’s say, Belgium, and be able to clear cache originated by calls from a machine in the UK and a machine in Portugal?

I hope I am making sense :slight_smile:

Thank you for any help and/or time spent.

I’m not entirely sure about what you want to accomplish, but do you think this can explain what you’re seeing?

The Cache API is available globally but the contents of the cache do not replicate outside of the originating data center. A GET /users response can be cached in the originating data center, but will not exist in another data center unless it has been explicitly created.

https://developers.cloudflare.com/workers/runtime-apis/cache

Hi, thanks for your time and reply.
I was aiming to be able to call the worker endpoint from a backend server to clear a specific cache, by url, that could have been originated on any data center.
This was to avoid changing the entire approach already in place, placing Cloudflare on top instead of having to introduce change to make it work.
From your reply, it looks like it might not be possible - that’s fine, I will design an alternative approach.
Thank you.

If you want to use the Cloudflare API to purge cached files then you can check out this endpoint. It will take a list of URLs can clear them. There is also this endpoint to clear all of your cache

Thank you @Jake1st - I have looked into it before but noticed the “The Cloudflare API sets a maximum of 1,200 requests in a five minute period.” message, which at the time was not ideal. I will look into it again. Cheers