This page describes how to invalidate your Cloud CDN cached content.
For example, if a file located at /images/file.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 Google Cloud CLI or the Google Cloud console to perform invalidations.
You can access the Google Cloud CLI in two ways:
Install the Google Cloud CLI by following the instructions at Installing with
apt-get
. If you haven't used the Google Cloud CLI previously, first rungcloud init
to authenticate.Use Cloud Shell, which comes with
gcloud
already installed.
To create a custom role with the required permissions, see Creating and managing custom roles.
To add a predefined role, use the IAM quickstart.
Invalidate only one file
Console
- In the Google Cloud console, go to the Cloud CDN page.
- Under Associated load balancers, click the load balancer name.
- Click the Cache invalidation tab.
- Enter the path to the file.
- If you want to invalidate a path for all hostnames, enter only the
path (for example:
/images/file.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/file.jpg
).
- If you want to invalidate a path for all hostnames, enter only the
path (for example:
- Click Invalidate.
gcloud
gcloud compute url-maps invalidate-cdn-cache LOAD_BALANCER_NAME \ --path "/images/file.jpg"
The external Application Load Balancer's name and the URL map's name are the same.
Replace LOAD_BALANCER_NAME
with the name of your
load balancer. To list your load balancers, use the
gcloud compute url-maps list
command.
Optional: To invalidate for only one host, add the --host
flag
(--host example.com
).
gcloud compute url-maps invalidate-cdn-cache LOAD_BALANCER_NAME \ --host HOSTNAME \ --path "/images/file.jpg"
By default, the Google Cloud CLI waits until the invalidation has
completed. To perform the invalidation in the background, append --async
to the command line.
Invalidate the whole directory
Console
- In the Google Cloud console, go to the Cloud CDN page.
- Under Associated load balancers, click the load balancer name.
- Click the Cache invalidation tab.
- 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/*
).
- If you want to invalidate the whole directory for all hostnames, enter
only the path and wildcard (for example:
- Click Invalidate.
gcloud
gcloud compute url-maps invalidate-cdn-cache LOAD_BALANCER_NAME \ --path "/images/*"
Replace LOAD_BALANCER_NAME
with the name of your
load balancer. To list your load balancers, use the
gcloud compute url-maps list
command.
Optional: To invalidate for only one host, add the --host
flag
(--host example.com
).
gcloud compute url-maps invalidate-cdn-cache LOAD_BALANCER_NAME \ --host HOSTNAME \ --path "/images/*"
By default, the Google Cloud CLI waits until the invalidation has
completed. To perform the invalidation in the background, append --async
to the command line.
Invalidate everything
Console
- In the Google Cloud console, go to the Cloud CDN page.
- Under Associated load balancers, click the load balancer name.
- Click the Cache invalidation tab.
- 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/*
).
- If you want to invalidate everything for all hostnames, enter only
- Click Invalidate.
gcloud
gcloud compute url-maps invalidate-cdn-cache LOAD_BALANCER_NAME \ --path "/*"
Replace the following:
LOAD_BALANCER_NAME
: the name of 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 LOAD_BALANCER_NAME \ --host HOSTNAME \ --path "/*"
By default, the Google Cloud CLI waits until the invalidation has
completed. To perform the invalidation in the background, append --async
to the command line.
What's next
- To check whether Cloud CDN is serving responses from cache, see Viewing logs.
- To learn about which content is cacheable or non-cacheable, see Caching overview.