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 thegcloud
command-line tool previously, first rungcloud init
to authenticate.Use Cloud Shell, which comes with
gcloud
already installed.
To create a custom role with the required permission, see Creating and managing custom roles.
To add a predefined role, use the IAM quickstart.
Invalidating only one file
Console
- In the Google Cloud Console, go to the Cloud CDN page.
- Click the origin name of the relevant origin.
- 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/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
).
- 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 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
- In the Google Cloud Console, go to the Cloud CDN page.
- Click the origin name of the relevant origin.
- 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 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
- In the Google Cloud Console, go to the Cloud CDN page.
- Click the origin name of the relevant origin.
- 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 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
- 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.
- To find GFE points of presence, see Cache locations.