This page provides an overview of Google Cloud CDN cache invalidation. To learn how to invalidate cached content, read Invalidating Cached Content.
What is cache invalidation?
Once an object is cached, it normally remains in the cache until it expires or is evicted to make room for new content. You control the expiration time through standard HTTP headers. For details, refer to the expiration times section in Caching Details.
Sometimes, you might want to remove an object from the cache prior to its normal expiration time. You can force an object, or set of objects, to be ignored by the cache by requesting a cache invalidation.
It is important to ensure the origin server is returning the correct content before you request the cache invalidation. Otherwise, when Cloud CDN re-requests the content, it may once again cache the still-incorrect content.
Each invalidation request specifies a path pattern that identifies the object
or set of objects that should be invalidated. The path pattern can be either a
specific path, such as
/cat.jpg, or an entire directory structure, such as
/pictures/*. The following rules apply to path patterns:
- The path pattern must start with
- It cannot include
- It must not include a
*except as the final character following a
- If it ends with
/*, the preceding string is a prefix, and all objects whose paths begin with that prefix are invalidated.
The path pattern is compared with the path component of the URL, which is
everything between the hostname and any
# that might be present.
If you have URLs that contain a query string, e.g.
you cannot selectively invalidate objects that differ only by query string.
For example, if you have two images,
/images.php?image=barney.png, you cannot invalidate only
fred.png. To invalidate all images served by images.php,
/images.php as the path pattern.
Invalidating the cache for a single host
Normally, cache invalidation invalidates the path for all your host names. For
example, if you have
example2.com pointed to the same
load balancer, and you invalidate
example2.com/images/cat.jpg are invalidated.
You can restrict the invalidation to only one of the hosts by adding the
--host flag to the command.
See Invalidating Cached Content for instructions.
Invalidation is intended for use in exceptional circumstances, not as part of your normal workflow. Importantly, invalidations don't affect cached copies in web browser caches or caches operated by third-party Internet service providers. As an alternative to routine invalidations, you can proactively set appropriate expiration times on responses and/or use different URLs for different versions of your content.
Invalidations are rate limited. You can submit at most one invalidation per
minute. But, an invalidation can be of any size. Invalidating
/images/fred.png counts as one invalidation. Invalidating
/images/* also counts as one invalidation.
Invalidate only what you must, because invalidating too much might cause a large spike of requests that were being served by the caches to suddenly hit your instances or buckets.
Because Cloud CDN is a distributed system, it might report that an invalidation has completed even though some small number of caches have not yet processed the invalidation request. This situation is extremely rare and will correct itself automatically.