Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Nesta página, fornecemos instruções para mudar os modos de cache com o
Cloud CDN. Os modos de cache permitem configurar como o Cloud CDN
armazena seu conteúdo em cache.
Clique no nome do seu balanceador de carga de aplicativo externo.
Clique em Editaredit.
Em Configuração de back-end, selecione um back-end e clique em Editaredit.
Verifique se a opção Ativar o Cloud CDN está selecionada.
Em Modo de cache, selecione uma das seguintes opções:
Armazene em cache o conteúdo estático (recomendado): são recursos da Web que não são alterados para cada usuário. O conteúdo estático é baseado no Content-Type na resposta. Para mais informações, consulte conteúdo estático.
Use as configurações de origem com base nos cabeçalhos de controle de cache: respostas de cache com diretivas de cache válidas nos cabeçalhos de resposta.
Forçar cache de todo o conteúdo: armazene em cache todo o conteúdo veiculado
pela origem, ignorando todas as diretivas private ou no-store.
CACHE_ALL_STATIC (padrão): armazena automaticamente o conteúdo estático em cache. As respostas marcadas
como não armazenáveis em cache (as diretivas private ou no-store
nos cabeçalhos de resposta Cache-Control) não são armazenadas. O conteúdo dinâmico precisa ter
cabeçalhos de cache válidos para ser armazenado em cache.
USE_ORIGIN_HEADERS: exige a origem para definir
cabeçalhos de cache válidos a fim de
armazenar conteúdo em cache. As respostas sem esses cabeçalhos não são armazenadas em cache na borda do Google e exigem uma viagem completa à origem em todas as solicitações, o que pode afetar o desempenho e aumentar a carga no servidor de origem.
FORCE_CACHE_ALL: armazena em cache todo o conteúdo (ou seja, respostas bem-sucedidas),
ignorando as diretivas private ou no-store nos cabeçalhos de resposta
Cache-Control. Isso pode resultar no armazenamento em cache de conteúdo particular
por usuário (identificação de usuários). Ative a função
somente em back-ends que não exibem conteúdo particular ou
dinâmico, como buckets do Cloud Storage. Não ative em back-ends que estejam veiculando conteúdo privado ou dinâmico.
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
Adicione o seguinte snippet ao corpo da solicitação JSON:
CACHE_ALL_STATIC (padrão): armazena em cache o conteúdo
estático automaticamente caso a origem não defina
cabeçalhos de cache válidos. As respostas marcadas
como não armazenáveis em cache (as diretivas private ou no-store
nos cabeçalhos de resposta Cache-Control) não são armazenadas. Para armazenar conteúdo
dinâmico em cache, o conteúdo precisa ter cabeçalhos de cache válidos.
USE_ORIGIN_HEADERS: exige a origem para definir cabeçalhos de cache válidos a fim de armazenar conteúdo em cache. As respostas sem esses cabeçalhos não são armazenadas em cache na borda do Google e exigem uma viagem completa à origem em todas as solicitações, o que pode afetar o desempenho e aumentar a carga no servidor de origem.
FORCE_CACHE_ALL: armazena em cache todo o conteúdo (ou seja, respostas bem-sucedidas),
ignorando as diretivas private ou no-store nos cabeçalhos de resposta
Cache-Control. Isso pode resultar no armazenamento em cache de conteúdo particular
por usuário (identificação de usuários). Ative a função somente em back-ends
que não exibem conteúdo particular ou dinâmico, como
buckets do Cloud Storage.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-11 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."]]