CDN cache lifecycle management
The current iteration of the CDN service does not provide a simple way to
manually clear the CDN cache. By default, each asset accessed through a VPN
endpoint will be cached with a TTL of 7 days when it is first accessed. The TTL
can customized by setting the expires
or cache-control
headers of the
source SOS object.
At 90% of the TTL, the object will be re-downloaded and the CDN cache will be updated with the new version if the object has been modified.
If you need more control over your CDN cache, you have two possible strategies you can use:
- Use versioning in your file naming scheme
- Use a short TTL
Versioning Naming Scheme
If you use a version naming scheme, you can serve different versions of your content while ensuring you can show your user new content before the cache expires.
There are 3 different strategies that you can use for a version naming scheme:
- Use a query string:
myfile.txt?v=101
- Add the version in the filename:
myfile.v101.txt
- Use a folder naming tree:
/v101/myfile.txt
Controlling the Cache TTL through Headers
You can set expires
or cache-control
on individual objects to indicate to the CDN provider that you want to use a different TTL other than the 7-day default.
Cache-Control
can for example be used to set a 72-hour TTL:
Cache-Control: public, max-age=259200
Or you can use Expires
to set the set date at which the content should be considered stale.
Expires: Wed, 21 Oct 2023 07:28:00 GMT
You can read more about HTTP headers on the MDN documentation: