Click the name of your external Application Load Balancer.
Click Editedit.
In Backend configuration, select a backend and click Editedit.
Make sure that Enable Cloud CDN is selected.
Under Cache mode, select one of the following options:
Cache static content (recommended): Static
content is web assets that don't change for each user. Static content is
based on the Content-Type in the response. For more information, see
static content.
Use origin settings based on Cache-Control headers: Cache
responses with valid cache directives
in the response headers.
Force cache all content: Cache all successful content served by
the origin, ignoring any private or no-store directives.
CACHE_ALL_STATIC (default): Automatically caches static
content. Responses that are
marked as uncacheable (private or no-store directives in
Cache-Control response headers) aren't cached. To cache dynamic content,
the content must have
valid caching headers.
USE_ORIGIN_HEADERS: 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, potentially
impacting performance and increasing load on the origin server.
FORCE_CACHE_ALL: Caches all content (that is, successful responses),
ignoring any private or no-store directives in Cache-Control
response headers. This might result in caching of private, per-user
(user identifiable) content. Only enable this on backends that
are not serving private or dynamic content, such as Cloud Storage
buckets. Don't enable this on backends that are serving private or dynamic
content.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets
PUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets/BACKEND_BUCKET
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices
PUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE
Add the following snippet to the JSON request body:
CACHE_ALL_STATIC (default): Automatically caches static
content if the origin does not set
valid caching headers. Responses that
are marked as uncacheable (private or no-store directives in
Cache-Control response headers) aren't cached. To cache dynamic content,
the content must have valid caching headers.
USE_ORIGIN_HEADERS: 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, potentially
impacting performance and increasing load on the origin server.
FORCE_CACHE_ALL: Caches all content (that is, successful responses),
ignoring any private or no-store directives in Cache-Control
response headers. This might result in caching of private, per-user
(user identifiable) content. You should only enable this on backends
that are not serving private or dynamic content, such as
Cloud Storage buckets.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThis page guides users on how to configure cache modes for Cloud CDN, which determines how content is cached.\u003c/p\u003e\n"],["\u003cp\u003eUsers can set cache modes to \u003ccode\u003eCache static content\u003c/code\u003e, \u003ccode\u003eUse origin settings based on Cache-Control headers\u003c/code\u003e, or \u003ccode\u003eForce cache all content\u003c/code\u003e via the Google Cloud console.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egcloud\u003c/code\u003e CLI can be used to set cache modes for backend services or buckets with the \u003ccode\u003e--cache-mode\u003c/code\u003e flag, offering options like \u003ccode\u003eCACHE_ALL_STATIC\u003c/code\u003e, \u003ccode\u003eUSE_ORIGIN_HEADERS\u003c/code\u003e, and \u003ccode\u003eFORCE_CACHE_ALL\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eCache modes can also be configured using API calls, specifically \u003ccode\u003eMethod: backendBuckets.insert/update\u003c/code\u003e and \u003ccode\u003eMethod: backendServices.insert/update\u003c/code\u003e, by modifying the \u003ccode\u003ecacheMode\u003c/code\u003e property in the request body's \u003ccode\u003ecdnPolicy\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eEach cache mode option (\u003ccode\u003eCACHE_ALL_STATIC\u003c/code\u003e, \u003ccode\u003eUSE_ORIGIN_HEADERS\u003c/code\u003e, \u003ccode\u003eFORCE_CACHE_ALL\u003c/code\u003e) has distinct implications on what type of content is cached and how, depending on the nature of the content being served.\u003c/p\u003e\n"]]],[],null,["# Change cache modes\n\nThis page provides instructions for changing cache modes with\nCloud CDN. Cache modes let you configure how Cloud CDN\ncaches your content.\n\nBefore you begin\n----------------\n\n- Read about [cache modes and static content](/cdn/docs/caching#cache-modes).\n\n- Ensure that Cloud CDN is enabled; for instructions, see\n [Using Cloud CDN](/cdn/docs/using-cdn).\n\n- If necessary, update to the latest version of the Google Cloud CLI:\n\n ```\n gcloud components update\n ```\n | **Note:** Make sure that you're using gcloud CLI version `309.0.0` or later.\n\nSetting the cache mode\n----------------------\n\nTo configure cache modes for a Cloud CDN-enabled backend, do the\nfollowing: \n\n### Console\n\n1. In the Google Cloud console, go to the **Load Balancing** page.\n\n [Go to the Load balancing page](https://console.cloud.google.com/networking/loadbalancing/list)\n2. Click the name of your external Application Load Balancer.\n3. Click **Edit** edit.\n4. In **Backend configuration** , select a backend and click **Edit** edit.\n5. Make sure that **Enable Cloud CDN** is selected.\n6. Under **Cache mode** , select one of the following options:\n - **Cache static content (recommended)** : Static content is web assets that don't change for each user. Static content is based on the `Content-Type` in the response. For more information, see [static content](/cdn/docs/caching#static).\n - **Use origin settings based on Cache-Control headers** : Cache responses with [valid cache directives](/cdn/docs/caching#cacheability) in the response headers.\n - **Force cache all content** : Cache all successful content served by the origin, ignoring any `private` or `no-store` directives.\n7. Click **Save**.\n\n### gcloud\n\nFor backend services, use the [`gcloud compute backend-services\ncreate`](/sdk/gcloud/reference/compute/backend-services/create) or\n[`gcloud compute backend-services\nupdate`](/sdk/gcloud/reference/compute/backend-services/update) command\nwith the `--cache-mode` flag.\n\nFor backend buckets, use the [`gcloud compute backend-buckets\ncreate`](/sdk/gcloud/reference/compute/backend-buckets/create) or\n[`gcloud compute backend-buckets\nupdate`](/sdk/gcloud/reference/compute/backend-buckets/update) command\nwith the `--cache-mode` flag. \n\n```\ngcloud compute backend-services (create | update) BACKEND_SERVICE_NAME\n --cache-mode=CACHE_MODE\n``` \n\n```\ngcloud compute backend-buckets (create | update) BACKEND_BUCKET_NAME\n --cache-mode=CACHE_MODE\n```\n\nReplace \u003cvar translate=\"no\"\u003eCACHE_MODE\u003c/var\u003e with one of the following:\n\n- `CACHE_ALL_STATIC` (default): Automatically caches [static\n content](/cdn/docs/caching#static). Responses that are\n marked as uncacheable (`private` or `no-store` directives in\n `Cache-Control` response headers) aren't cached. To cache dynamic content,\n the content must have\n [valid caching headers](/cdn/docs/caching#cacheability).\n\n- `USE_ORIGIN_HEADERS`: Requires the origin to set\n [valid caching headers](/cdn/docs/caching#cacheability) to\n cache content. Responses without these headers aren't cached at Google's\n edge and require a full trip to the origin on every request, potentially\n impacting performance and increasing load on the origin server.\n\n- `FORCE_CACHE_ALL`: Caches all content (that is, successful responses),\n ignoring any `private` or `no-store` directives in `Cache-Control`\n response headers. This might result in caching of private, per-user\n (user identifiable) content. Only enable this on backends that\n are not serving private or dynamic content, such as Cloud Storage\n buckets. Don't enable this on backends that are serving private or dynamic\n content.\n\n### API\n\nFor backend buckets, use the\n[`Method: backendBuckets.insert`](/compute/docs/reference/rest/v1/backendBuckets/insert) or\n[`Method: backendBuckets.update`](/compute/docs/reference/rest/v1/backendBuckets/update)\nAPI call.\n\nFor backend services, use the\n[`Method: backendServices.insert`](/compute/docs/reference/rest/v1/backendServices/insert) or\n[`Method: backendServices.update`](/compute/docs/reference/rest/v1/backendServices/update)\nAPI call.\n\nUse one of the following API calls: \n\n```\nPOST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets\nPUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendBuckets/BACKEND_BUCKET\nPOST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices\nPUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE\n```\n\nAdd the following snippet to the JSON request body: \n\n```\n\"cdnPolicy\": {\n \"cacheMode\": (CACHE_ALL_STATIC | USE_ORIGIN_HEADERS | FORCE_CACHE_ALL)\n```\n\nReplace \u003cvar translate=\"no\"\u003eCACHE_MODE\u003c/var\u003e with one of the following:\n\n- `CACHE_ALL_STATIC` (default): Automatically caches [static\n content](/cdn/docs/caching#static) if the origin does not set\n [valid caching headers](/cdn/docs/caching#cacheability). Responses that\n are marked as uncacheable (`private` or `no-store` directives in\n `Cache-Control` response headers) aren't cached. To cache dynamic content,\n the content must have [valid caching headers](/cdn/docs/caching#cacheability).\n\n- `USE_ORIGIN_HEADERS`: Requires the origin to set [valid caching\n headers](/cdn/docs/caching#cacheability) to\n cache content. Responses without these headers aren't cached at Google's\n edge and require a full trip to the origin on every request, potentially\n impacting performance and increasing load on the origin server.\n\n- `FORCE_CACHE_ALL`: Caches all content (that is, successful responses),\n ignoring any `private` or `no-store` directives in `Cache-Control`\n response headers. This might result in caching of private, per-user\n (user identifiable) content. You should only enable this on backends\n that are not serving private or dynamic content, such as\n Cloud Storage buckets."]]