Skip to content

Clear the cache

View as Markdown

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.

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.

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/*.

  1. In MyAccount, under Network, click CDN. On Manage CDN Services, click the distribution.
  2. Open the Invalidations tab, and click Flush Cache. Create New Invalidation opens, showing the distribution’s Domain and Domain Id.
  3. In Object paths, enter one or more paths, separated by spaces, commas, or new lines.
  4. 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.

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.jpg

Replace <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.

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.