Invalidating a CDN cache in a Worker
# workers-help
j
Hey Cloudflare folks, We have a setup where we have a set of SDKs who connect to worker APIs where we access a set of CF CDN cached S3 JSON files in our workers. When those files are updated by one of our backend services we trigger the purge cache API to purge the CDN globally for that file. After that purge cache API request we also trigger a message, through a live SSE connection connected to all active SDKs for that project, to trigger a new request to our CF Worker APIs to fetch new configurations. Generally we see this setup work well as purging the CDN cache can be surprisingly fast, however there are situations where the local CDN cache in certain data centers haven't been purged yet. As a part of the SSE message and the request we make to our workers, we send the
sseLastModified
time that we use to compare against the
Last-Modified
header of the CDN response. We are struggling to figure out the best way to invalidate the local data center cache from the worker without triggering many new requests to the global purge cache API. The options we see are: - Call the global purge cache API: https://developers.cloudflare.com/cache/how-to/purge-cache/#purge-by-single-file-by-url - Will calling DELETE on the Worker Cache API invalidate the local cache for a fetch request to the CDN? (this wasn't clear in the docs): https://developers.cloudflare.com/workers/runtime-apis/cache/#delete - Can this be accomplished by using the
cf.cacheTtl = 0
property on our fetch request or some other property (we are an enterprise customer): https://developers.cloudflare.com/workers/runtime-apis/request/#requestinitcfproperties Thanks for your help! Jonathan Norris