Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En esta página, se proporcionan instrucciones para cambiar los modos de almacenamiento en caché con Cloud CDN. Los modos de almacenamiento en caché te permiten configurar cómo Cloud CDN almacena en caché tu contenido.
Haz clic en el nombre de tu balanceador de cargas de aplicaciones externo.
Haz clic en Editaredit.
En Configuración de backend, selecciona un backend y haz clic en Editaredit.
Asegúrate de que la opción Habilitar Cloud CDN esté seleccionada.
En Modo de almacenamiento en caché, selecciona una de las siguientes opciones:
Almacena el contenido estático en caché (recomendado): El contenido estático consiste en recursos web que no cambian para cada usuario. El contenido estático se basa en el Content-Type en la respuesta. Para obtener más información, consulta contenido estático.
Usa la configuración de origen en función de los encabezados Cache-Control: Almacena en caché respuestas con directivas de caché válidas en los encabezados de respuesta.
Fuerza el almacenamiento en caché de todo el contenido: Almacena en caché todo el contenido que entrega el origen, sin importar las directivas private o no-store.
Reemplaza CACHE_MODE por uno de los siguientes valores:
CACHE_ALL_STATIC (predeterminado): Almacena en caché el contenido estático de forma automática. Las respuestas con
la marca de que no pueden almacenarse en caché (directivas private, no-store en encabezados de respuesta Cache-Control) no se almacenan en caché. Para almacenar en caché contenido dinámico,
el contenido debe tener
encabezados de almacenamiento en caché válidos.
USE_ORIGIN_HEADERS: Se requiere que se configuren encabezados de almacenamiento en caché válidos para el contenido de la caché en el origen. Las respuestas sin estos encabezados no se almacenan en caché en el extremo de Google y requieren un recorrido completo al origen en cada solicitud, lo que podría afectar el rendimiento y aumentar la carga en el servidor de origen.
FORCE_CACHE_ALL: Almacena en caché todo el contenido (es decir, respuestas correctas), ignorando las directivas private o no-store en los encabezados de respuesta Cache-Control. Esto podría provocar que se almacene en caché el contenido privado por usuario (lo que permita identificarlo). Solo se debería habilitar en backends que no entreguen contenido dinámico ni privado, como los buckets de Cloud Storage. No habilites esta opción en backends que entregan contenido privado o 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
Agrega el siguiente fragmento al cuerpo de la solicitud JSON:
Reemplaza CACHE_MODE por uno de los siguientes valores:
CACHE_ALL_STATIC (predeterminado): Almacena en caché el contenido estático de forma automática si el origen no establece encabezados de almacenamiento en caché válidos. Las respuestas con la marca de que no pueden almacenarse en caché (directivas private o no-store en encabezados de respuesta Cache-Control) no se almacenan en caché. Para almacenar en caché contenido dinámico, el contenido debe tener encabezados de almacenamiento en caché válidos.
USE_ORIGIN_HEADERS: Se requiere que se configuren encabezados de almacenamiento en caché válidos para el contenido de la caché en el origen. Las respuestas sin estos encabezados no se almacenan en caché en el extremo de Google y requieren un recorrido completo al origen en cada solicitud, lo que podría afectar el rendimiento y aumentar la carga en el servidor de origen.
FORCE_CACHE_ALL: Almacena en caché todo el contenido (es decir, respuestas correctas), ignorando las directivas private o no-store en los encabezados de respuesta Cache-Control. Esto podría provocar que se almacene en caché el contenido privado por usuario (lo que permita identificarlo). Solo se debería habilitar en backends que no entreguen contenido dinámico ni privado, como buckets de Cloud Storage.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-05 (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."]]