Invalidating cached content

This page describes how to invalidate your Cloud CDN cached content.

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

To learn more about cache invalidation, see Cache invalidation overview.

Before you begin

You can use the gcloud command-line interface or the Google Cloud Console to perform invalidations.

You can access the gcloud command-line tool in two ways:

  • Install the Cloud SDK by following the instructions at Installing with apt-get. If you haven't used the gcloud command-line tool previously, first run gcloud init to authenticate.

  • Use Cloud Shell, which comes with gcloud already installed.

Invalidating only one file

Console

  1. In the Google Cloud Console, go to the Cloud CDN page.

    Go to the Cloud CDN page

  2. Click the origin name of the relevant origin.
  3. Click the Cache invalidation tab.
  4. Enter the path to the file.
    • If you want to invalidate a path for all hostnames, enter only the path (for example: /images/foo.jpg).
    • If you want to invalidate a path for only one hostname, specify 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"

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

Invalidating the whole directory

Console

  1. In the Google Cloud Console, go to the Cloud CDN page.

    Go to the Cloud CDN page

  2. Click the origin name of the relevant origin.
  3. Click the Cache invalidation tab.
  4. Enter the directory path and wildcard (/path/to/file/*).
    • If you want to invalidate the whole directory for all hostnames, enter only the path and wildcard (for example: /images/*).
    • If you want to invalidate the whole directory for only one hostname, 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/*"

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

Invalidating everything

Console

  1. In the Google Cloud Console, go to the Cloud CDN page.

    Go to the Cloud CDN page

  2. Click the origin name of the relevant origin.
  3. Click the Cache invalidation tab.
  4. Enter only the root and the wildcard (/*).
    • If you want to invalidate everything for all hostnames, enter only /* into the field.
    • If you want to invalidate everything for only one hostname, 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 "/*"

Replace the following:

  • URL_MAP_NAME: the name of the URL map resource in your load balancer
  • /*: the URL path that you want to invalidate; does not include the hostname; the path can 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