I can’t find a non-manual way to purge the cache of a file in the CDN after I update it in Spaces. I feel like this is a common task but I can’t find any documentation on it besides the one telling you how to do it manually through DO’s website.
How can we purge the cache of a file after an update through an API?
FYI I’m updating files through the aws-sdk S3 API.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Clarifying @jarland’s answer a bit: The Spaces API itself does not have support for purging the CDN’s cache, but the DigitalOcean platform API does. The Spaces API was designed to emulate the AWS S3 API so that developers could use it as a drop-in replacement for S3 existing projects. Spaces-specific functionality like the builtin CDN are not part of the S3 API but are support in the DigitalOcean API.
First you’ll need to find the ID of you CDN endpoint. You can do that by listing your CDN endpoints using:
Then you can purge the cache with:
That command would purge the entire cache, but you could list specific files as well.
The DigitalOcean CLI, doctl, supports these as well:
To list the CDN endpoints run:
And to purge the cache, run:
Find the full API reference docs here: https://developers.digitalocean.com/documentation/v2/#cdn-endpoints
Greetings!
Great question. To purge the cache you would need to go through the control panel, but this is probably not the ideal method for automation. Instead, you should focus on the TTL. This document will give you a bit more insight into that:
https://www.digitalocean.com/docs/spaces/how-to/manage-cdn-cache
You can set the TTL for the whole space or individual files (whole space being a bit easier). Once TTL is reached, the CDN should refresh it’s cache.
Jarland
Me too … looking for a similar solution!
Thanks