Invalidating Cached Content

This page describes how to invalidate your Google Cloud CDN cached content. To learn more about cache invalidation, read Cache Invalidation Overview.

Before you begin

Install the gcloud command-line tool.

If you haven't run the gcloud command-line tool command previously, first run gcloud init to authenticate.

Invalidating cached content

You can perform invalidations using using the gcloud command-line interface or the Google Cloud Platform Console.

Examples

If a file located at /images/foo.jpg has been cached and needs to be invalidated, there are several methods you can use to invalidate it, depending on whether you wanted to affect just that file or a wider scope. In each case, you can invalidate for all hostnames or for just one hostname.

To invalidate just one file:

Console


  1. Go to the Cloud CDN page in the Google Cloud Platform Console.
    Go to the Cloud CDN page
  2. Click on the origin name of the relevant origin.
  3. Click Cache invalidation.
  4. Enter the path to the file.
    • If you want to invalidate a path for all hostnames, enter just the path. (Ex: /images/foo.jpg)
    • If you want to invalidate a path for one hostname only, specify the the hostname as part of the path. (For example: example.com/images/foo.jpg)
  5. Click Invalidate.

gcloud


gcloud compute url-maps invalidate-cdn-cache [URL_MAP_NAME] \
    --path "/images/foo.jpg"

  • [URL_MAP_NAME] - The name of the URL map resource in your load balancer.

Optional: To invalidate for only one host, add the --host flag. (--host example.com)

gcloud compute url-maps invalidate-cdn-cache [URL_MAP_NAME] \
    --host [HOSTNAME] \
    --path "/images/foo.jpg"

By default, the gcloud command-line tool waits until the invalidation has completed. To perform the invalidation in the background, append --async to the command line.

To invalidate the whole directory:

Console


  1. Go to the Cloud CDN page in the Google Cloud Platform Console.
    Go to the Cloud CDN page
  2. Click on the origin name of the relevant origin.
  3. Click Cache invalidation.
  4. Enter the directory path and wildcard (/path/to/file/*).
    • If you want to invalidate the whole directory for all hostnames, enter just the path and wildcard. (Ex: /images/*)
    • If you want to invalidate the whole directory for one hostname only, specify the hostname as part of the path. (For example: example.com/images/*)
  5. Click Invalidate.

gcloud


gcloud compute url-maps invalidate-cdn-cache [URL_MAP_NAME] \
    --path "/images/*"

  • [URL_MAP_NAME] - The name of the URL map resource in your load balancer.

Optional: To invalidate for only one host, add the --host flag. (--host example.com)

gcloud compute url-maps invalidate-cdn-cache [URL_MAP_NAME] \
    --host [HOSTNAME] \
    --path "/images/*"

By default, the gcloud command-line tool waits until the invalidation has completed. To perform the invalidation in the background, append --async to the command line.

To invalidate everything:

Console


  1. Go to the Cloud CDN page in the Google Cloud Platform Console.
    Go to the Cloud CDN page
  2. Click on the origin name of the relevant origin.
  3. Click Cache invalidation.
  4. Enter just the root and the wildcard (/*).
    • If you want to invalidate everything for all hostnames, enter just /* into the field.
    • If you want to invalidate everything for one hostname only, specify the hostname as part of the path. (For example: example.com/*)
  5. Click Invalidate.

gcloud


gcloud compute url-maps invalidate-cdn-cache [URL_MAP_NAME] \
    --host [HOSTNAME] \
    --path "/*"

  • [URL_MAP_NAME] - The name of the URL map resource in your load balancer.
  • path - The URL path you wish to invalidate. Does not include the host name. The path may use an explicit filename or a wildcard.

Optional: To invalidate for only one host, add the --host flag. (--host example.com)

gcloud compute url-maps invalidate-cdn-cache [URL_MAP_NAME] \
    --host [HOSTNAME] \
    --path "/*"

By default, the gcloud command-line tool waits until the invalidation has completed. To perform the invalidation in the background, append --async to the command line.

What's next

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud CDN Documentation