Business Challenge
#107 ended on the backend service being the resource that decides eligibility for the features hanging off it. Cloud CDN is the first of those, and it is configured in the same place: you can configure caching behavior for Cloud CDN at the backend service, backend bucket, or at a more granular level in URL maps.
Enabling it is one checkbox. What that checkbox buys you depends entirely on a second setting next to it, and the three values that setting takes are named in a way that makes two of them sound stronger than they are and one sound weaker.
Two different causes, and which one you have depends on the mode. Under USE_ORIGIN_HEADERS the CDN delegates the whole decision to your application: it requires the origin to set valid caching headers to cache content. Responses without these headers aren't cached at Google's edge and require a full trip to the origin on every request. No headers, no caching, no warning.
Under the default CACHE_ALL_STATIC the cause is usually what counts as static. Other content types, such as HTML (text/html) and JSON (application/json), are not cached by default for successful responses. If your traffic is an API or server-rendered pages, the default mode was never going to cache the part you care about.
Decide who owns cacheability before picking a mode, because that is the only thing the mode chooses. If the application already emits deliberate cache headers, USE_ORIGIN_HEADERS respects them exactly. If it does not and you want static assets cached anyway, CACHE_ALL_STATIC covers them without application changes. And if the answer you want is HTML, the mode is not the fix — the headers are.
Then something in the response is outside what that mode overrides. The common one is Vary: Google allows a short list of values, and other Vary header values prevent content from being cached. The FORCE_CACHE_ALL cache mode does not override this behavior.
That exception is designed in rather than left over. The Vary headers are important to avoid cache poisoning between multiple possible origin server responses. It would be dangerous for FORCE_CACHE_ALL to cause those responses to be cached. A response that says it varies by something the cache is not keying on cannot be stored safely, and no setting is allowed to say otherwise.
Correct approach
Read the mode's name as a claim about cache directives only. FORCE_CACHE_ALL ignores private and no-store; it does not ignore Vary, and it does not raise the maximum response size. If a response varies on a header that genuinely matters, the fix is to put that header into the cache key rather than to find a stronger mode.
This is the failure the cache-key documentation opens with, before any instructions: excluding components from cache keys can cause Cloud CDN to serve content intended for one user to another. Drop the query string from the key and every variant of a URL becomes one cached object.
There are two other routes to the same outcome. FORCE_CACHE_ALL is explicit that it might result in caching of private, per-user (user identifiable) content, and separately: when content is accessed by using a signed URL, it is potentially eligible for caching regardless of any Cache-Control directives in the response.
Treat a cache-key change as a security change and not a performance one. Before removing a component, establish that no response varies on it — which is a statement about the application, not about the CDN. And keep per-user content behind a backend whose mode is not FORCE_CACHE_ALL: Google's own instruction is to only enable this on backends that are not serving private or dynamic content, such as Cloud Storage buckets.
Architecture
One checkbox, then four decisions that the checkbox does not make.
The mode chooses who owns cacheability
Read the three descriptions as answers to one question — whose judgement decides whether a response is cacheable — and they stop being three similar settings.
USE_ORIGIN_HEADERS answers "the application's". CACHE_ALL_STATIC answers "the application's, with a content-type fallback": automatically caches static content. Responses that are marked as uncacheable (private or no-store directives in Cache-Control response headers) aren't cached. FORCE_CACHE_ALL answers "yours, overriding the application": caches all content (that is, successful responses), ignoring any private or no-store directives in Cache-Control response headers.
Which is why the middle one is the default and the last one carries a warning. This setting can lead to the unintentional caching of private or per-user content. The mode that needs no cooperation from the origin is precisely the mode that cannot be told no.
"Static" is a Content-Type, never a file extension
This is the single most common wrong mental model, and the documentation disposes of it directly: Cloud CDN doesn't use file extensions in the URL path to determine whether a response is cacheable because many valid cacheable responses aren't reflected in URLs. A path ending .js is not evidence of anything; the response's MIME type is the whole test.
And passing that test is necessary rather than sufficient. If a response is cacheable based on its MIME type but has a Cache-Control response header of private or no-store, or a Set-Cookie header, it isn't cached. That last clause is worth dwelling on: a framework that sets a session cookie on every response, including responses for static assets, has switched the CDN off for those assets, and nothing in the console says so.
The cache key: the same default, two opposite meanings
For backend services, Cloud CDN defaults to using the complete request URI as the cache key. Protocol, host and the entire query string are all in, so two requests differing only in a query parameter are two independent cached objects.
Move the same content to a bucket and the default inverts. For backend buckets, the default is for the cache key to consist of the URI without the protocol or host. By default, only query parameters that are known to Cloud Storage are included as part of the cache key. The reasoning is specific to the origin: backend buckets don't include the protocol or host in the cache key because these don't influence how objects are referenced within a Cloud Storage bucket. A set of URIs that were distinct objects behind a backend service collapse to one behind a bucket.
From there the customisation is a matter of what you add back. While the filename and path must always be part of the key, you can include or omit any combination of protocol, host, or query string when customizing your cache key. Two details save time: the generated cache key doesn't depend on the order of the query parameters, and the bucket case is include-only — because including query parameters in the cache key is opt-in only, Cloud CDN doesn't support excluding query parameters from a cache key to a backend bucket.
Headers and cookies can go into the key too, with guardrails that are really a lesson in cardinality. Some headers are not allowed in cache keys because they are typically very high cardinality — the example given is that the User-Agent header can have over 5,000 unique values given the large variety of browsers, user-devices, and operating systems. Cookies are capped: you can provide a list of up to five cookie names, and if a request includes multiple instances of the same cookie name, only the first one is honored.
One behaviour here will make a test look broken. Cache requests that include additional HTTP headers or HTTP cookies in the request are cached on the third request in a cache location for that cache key. Hit the URL twice from one location, see two misses, and conclude the configuration failed — when the configuration is working exactly as designed.
Which TTL is live depends on the mode
Three TTL settings exist, and it is tempting to read them as three dials that are always available. They are not. When you set the cache mode to use origin headers (USE_ORIGIN_HEADERS), the default TTL value doesn't apply and cannot be set; max TTL is only used when the cache mode is CACHE_ALL_STATIC; and with FORCE_CACHE_ALL, the TTL is always set to the default TTL; you can't set a max TTL.
The modes also differ in whether the TTL leaks to the client. Under FORCE_CACHE_ALL the default TTL overwrites the TTL set in all responses (including those that have a TTL set by origin headers), and in this mode, the default TTL is visible to clients, because Cloud CDN sets the public and max-age attributes of the responses served to clients. Under the default mode it does not: in CACHE_ALL_STATIC mode, the default TTL doesn't modify the Cache-Control header served to clients.
The values themselves are modest where it matters. Default TTL 3600s sets a 1-hour cache duration if the origin provides no headers; Max TTL 86400s is the absolute maximum time (24 hours) an object remains in the cache; Client TTL 3600s sets a 1-hour max-age for the client's browser cache; and all three share one ceiling — default value 3600 seconds (1 hour), 86,400 seconds (1 day), 3600 seconds (1 hour); max allowed value 31,622,400 seconds (1 year).
Two limits sit above all of that and are easy to miss. By default, when the expiration time value exceeds 30 days (2,592,000 seconds), Cloud CDN treats the expiration value as if it were 2,592,000 seconds, and separately cache entries that aren't accessed for 30 days are automatically evicted. A one-year TTL is a statement of intent, not a guarantee of residency.
Header precedence, and the typo that caches nothing
When an origin sends several cache headers, one wins outright. CDN-Cache-Control is first, and the wording is absolute: if present, Cloud CDN uses these directives exclusively and ignores any standard headers below it. This header is preserved and forwarded downstream to the client. Cache-Control is consulted only in its absence, and Cloud CDN ignores targeted cache control headers intended for specific third-party CDNs.
"Exclusively" has teeth. If a CDN-Cache-Control header is present in the response, Cloud CDN commits to using it. If the header contains syntax errors, parsing issues, or invalid values, such as a non-numeric max-age, Cloud CDN doesn't fall back to evaluate the standard Cache-Control header. A malformed targeted header does not degrade to the standard one; it takes the response out of the cache. The same trap exists one level down, where s-max-age (two hyphens) is not valid for the purposes of caching.
In the other direction, one client-supplied directive is deliberately disregarded: the no-cache request directive is ignored to prevent clients from potentially initiating or forcing revalidation to the origin. A client cannot force a cache bypass, which is a reasonable thing for a CDN to insist on and a surprising thing the first time a test with Cache-Control: no-cache returns a cached response anyway.
Why This Architecture Holds Up
Set out the paths by which per-user content ends up in a shared cache and the shape of this feature becomes clear. One is explicit and warned about: FORCE_CACHE_ALL. One is a configuration mistake with no error: removing a component from the cache key. And one has nothing to do with caching settings at all.
That third one is the interesting one. When content is accessed by using a signed URL, it is potentially eligible for caching regardless of any Cache-Control directives in the response. Signed URLs are an access-control feature; reaching for one to protect a private object also makes that object cacheable, and the documentation's advice is correspondingly blunt — do not sign URLs that provide access to private information.
Against that, the protections that do exist are narrow and specific. The Authorization header gets one: for origin (cache fill) requests that include the Authorization request header, Cloud CDN only caches responses that include the public, must-revalidate, or s-maxage cache control directives when the cache mode is set to USE_ORIGIN_HEADERS or CACHE_ALL_STATIC. And then, immediately: the FORCE_CACHE_ALL cache mode does not have this restriction.
So the mode that overrides the most is the mode that also removes the guard specifically designed for authenticated requests. Which is the real reason its name misleads. It is not that it forces too little — Vary stops it, and deliberately. It is that where it does apply, it applies to exactly the responses you would most want it not to.
Negative caching, where the defaults stop applying the moment you configure it
Negative caching lets you set a different time to live (TTL) for each status code, which is how you stop a hot 404 from reaching the origin on every request. It is off to begin with — Negative Caching false; error responses, such as, 404s are not cached by default — and enabling it with no policy gives you Google's values: if you omit the policy and have negativeCaching enabled, Cloud CDN uses the default values listed in Status codes and default TTLs, which include HTTP 404 Not found 120 seconds, HTTP 405 Method not found 60 seconds.
The trap is in writing a partial policy. Cloud CDN doesn't apply any default negative caching when a policy exists. List 404 alone and every other status code silently reverts to uncached — a policy that looks like it adds one rule actually removes eight. The whole feature is also bounded: the maximum allowed value is 1800 seconds (30 minutes).
Key Architecture Decisions
| Situation | Decision | Because |
|---|---|---|
| Application already emits deliberate cache headers | USE_ORIGIN_HEADERS |
The headers are the design; the mode just respects them. |
| Static assets, no application changes available | CACHE_ALL_STATIC (the default) |
Content-type fallback covers them without touching the origin. |
| Public bucket of immutable objects | FORCE_CACHE_ALL, and nowhere else |
Google's instruction is to enable it only on backends not serving private or dynamic content. |
| Mode set to force and still not caching | Look at Vary, not at the mode |
Force does not override Vary, by design, to avoid cache poisoning. |
| Needing HTML or JSON cached | Emit cache headers; do not change mode | Those content types are not cached by default in any mode. |
| Responses vary per user on a parameter | Leave the query string in the key | Excluding a component can serve one user's content to another. |
| Cache-busting objects in a bucket | Query string include list | Exclude lists are not supported for backend buckets. |
| Wanting per-device or per-region variants | Named headers in the key, sparingly | High-cardinality headers are blocked precisely to protect hit rate. |
| Testing a header-keyed configuration | Expect the hit on the third request | Header- and cookie-keyed requests are cached on the third request. |
| Protecting the origin from error floods | Negative caching, with every code listed | Once a policy exists, no defaults apply to codes you omitted. |
| Different TTLs per path on one backend | Cache policies in the URL map | Global external Application Load Balancer only, not classic. |
Using CDN-Cache-Control |
Validate the syntax in CI | A malformed value does not fall back — it goes uncached. |
The one to look at today
For every backend with Cloud CDN enabled, write down three things: the cache mode, the cache key components, and whether any response from that backend is per-user. If the third answer is yes and the mode is FORCE_CACHE_ALL, or any key component has been removed, you have the conditions for serving one user's content to another — and neither state produces an error anywhere. While there, check whether a negative caching policy exists and lists fewer status codes than you assumed; that one is a quiet regression rather than a leak, but it is just as invisible.
Closing Thought
Every setting in this post is named after what it does to cache directives, and every surprise in it comes from something that is not a cache directive. Vary stops the forcing mode. A Set-Cookie header disables caching for a response whose content type qualifies. A signed URL, which exists for access control, makes private content cacheable. The origin type — service or bucket — silently changes what the default cache key means.
Which is a version of the lesson #107 closed on, one layer up. There, a number that read like a limit turned out to be a weight. Here, three modes that read like levels of aggressiveness turn out to be answers to a different question entirely: not how hard to cache, but whose judgement about cacheability the edge is going to accept.
#109 takes the other feature that attaches to the backend service: Cloud Armor — security policies, rule evaluation order and the web application firewall, where the thing being decided is not whether to store a response but whether to let the request through at all.
Comments