Caching Details


Not all HTTP responses are cacheable. Google Cloud CDN caches only those responses that meet all the requirements in this section. Some of these requirements are specified by RFC 7234, and others are specific to Cloud CDN.

A response can be stored in Cloud CDN caches only if all of the following are true:

  • It was served by a backend service with caching enabled.
  • It was a response to a GET request.
  • The status code was 200, 203, 300, 301, 302, 307, or 410.
  • It has a Cache-Control: public directive.
  • It has a Cache-Control: s-maxage, Cache-Control: max-age, or Expires header.
  • It has either a Content-Length header or a Transfer-Encoding header.

Additionally, there are checks that will block caching of responses. A response will not be cached if any of the following are true:

  • It has a Set-Cookie header.
  • Its body exceeds 10 MB.
  • It has a Vary header with a value other than Accept, Accept-Encoding, or Origin.
  • It has a Cache-Control: no-store, no-cache, or private directive.
  • The corresponding request had a Cache-Control: no-store directive.

These requirements might be relaxed in the future, allowing Cloud CDN to cache additional responses. To prevent a response from being cached, include a Cache-Control: no-store header if the response should not be stored in any cache, even a web browser's cache, or a Cache-Control: private header if it should not be stored in Cloud CDN caches.

Cache entries, keys, and variants

Each cache entry in a Cloud CDN cache is identified by a cache key. Cloud CDN incorporates the complete request URI into the cache key. For example, a request for cannot be satisfied using a cache entry that was created for (because the query string portion of the URLs differ) or (because the scheme and authority portions of the URLs differ). A request URI is the same as a URL except that request URIs exclude any trailing fragment identifiers. For example, given the URL, the request URI is

In addition to the request URI, Cloud CDN respects any Vary headers that instances include in responses. The Vary header indicates that the response varies depending on the client's request headers. For example, if a response specifies Vary: Accept, Cloud CDN will use one cache entry for requests that specify Accept: image/webp,image/*,*/*;q=0.8 and another for requests that specify Accept: */*.

Expiration times and validation requests

Each cache entry in a Cloud CDN cache has an expiration time defined by the Cache-Control: s-maxage, Cache-Control: max-age, and/or Expires headers in accordance with RFC 7234. If more than one is present, Cache-Control: s-maxage takes precedence over Cache-Control: max-age, and Cache-Control: max-age takes precedence over Expires.

When Cloud CDN receives a request, it looks up the corresponding cache entry and checks its age. If the cache entry exists and is fresh enough, the response can be served from cache. If, however, the expiration time has passed, Cloud CDN will forward the request through your load balancer to one of your instances.

If the previously cached response has a Last-Modified and/or ETag header, Cloud CDN can make the forwarded request conditional by adding If-Modified-Since and/or If-None-Match headers. If the cached copy is still up to date, the web server software on your instance can validate the existing cache entry by sending a 304 Not Modified response. In this case, your instance sends only the response headers, not the response body. Cloud CDN inserts the new response headers into the cache, update the expiration time, and serve the new response headers and cached response body to the client.

Note that the expiration time is an upper bound on how long a cache entry remains valid. There is no guarantee that a cache entry will remain in the cache until it expires. Cache entries for unpopular content can be evicted to make room for new content. Regardless of the specified expiration time, cache entries that aren't accessed for 30 days are automatically removed.

What's next

Send feedback about...

Cloud CDN Documentation