The CDN keeps a copy of each file at its edge locations until the file’s TTL runs out. When you change a file at your origin, visitors keep getting the cached copy until then. To serve the new version sooner, clear the file from the cache with an invalidation. The next request for each file you clear is fetched from your origin.
Before you begin
Section titled “Before you begin”Put the new version of the file at your origin first, such as in your bucket. Clearing the cache before that only fetches the old file again.
Choose the paths
Section titled “Choose the paths”You clear files by their paths on the distribution, each starting with /:
- The root address:
/. - One file:
/images/image1.jpg. - Every file in a folder:
/images/*. - Every file whose name starts with the same letters:
/images/image*. - Every file:
/*.
A * works only at the end of a path; anywhere else it counts as a character. A path without a
leading / gets one.
A path cannot contain an underscore, a vertical bar, or any of
` ! @ # $ % ^ & ( ) + = [ ] { } ; ' : " \ < > ? ~. To clear a file whose name has one of
these characters, clear its whole folder with *, such as /images/*.
Clear the files
Section titled “Clear the files”- In MyAccount, under Network, click CDN. On Manage CDN Services, click the distribution.
- Open the Invalidations tab, and click Flush Cache. Create New Invalidation opens, showing the distribution’s Domain and Domain Id.
- In Object paths, enter one or more paths, separated by spaces, commas, or new lines.
- Click Flush Cache in the dialog.
Your Invalidation has been created successfully. confirms it. A path with a character that is not allowed gets Please enter the valid object paths, and nothing is sent; change the path and try again.
Check that the files are cleared
Section titled “Check that the files are cleared”The invalidation is listed on Invalidations with Invalidation ID, Invalidations Paths, Status, and Created On (IST). Status reads InProgress until the edge locations have dropped the files, then Completed.
Once it reads Completed, ask for the file at the Distribution URL:
curl -I https://<distribution-url>/images/image1.jpgReplace <distribution-url> with the distribution’s Distribution URL, and the path with your
file’s. The headers, such as last-modified or content-length, match the new file at your origin.
Avoid clearing the cache
Section titled “Avoid clearing the cache”Query strings do not change what is cached: /images/logo.png?v=2 gets the same cached file as
/images/logo.png. To publish a changed file without clearing the cache, give it a new name, such
as /images/logo-v2.png, and link the new name from your pages. When your origin sends no caching
headers, a shorter Default TTL also makes changed files show sooner; see
How long files stay cached.
Visitors now get the new version of each file you cleared. If they still get the old one, see Troubleshooting CDN.