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, if the object has been modified it will be re-downloaded and the CDN cache will be updated with the new version.
If you need more control on your CDN cache, you need to employ one of the following strategies:
- Use versionning in your file naming scheme
- Use short TTL
Versioning naming scheme
Using a versioning naming scheme allow to serve different version of your content while ensuring you can show your user new content before the cache expiration.
There are 3 differents strategies that you can employ:
- using a query string: myfile.txt?v=101
- adding the version in the filename: myfile.v101.txt
- using folder naming tree: /v101/myfile.txt
Controling the cache TTL through headers
You can set expires
or cache-control
on each individual objects to indicate to the CDN provider you want to use as different TTL than the 7 days default.
Cache-Control
can for exemple be used to set a 72h TTL:
Cache-Control: public, max-age=259200
Or you can use the Expires
to set a set date at which the content should be considered stale.
Expires: Wed, 21 Oct 2015 07:28:00 GMT
Detailed documentation about the use of those headers can be found on the MDN documentation: