Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini memberikan petunjuk untuk mengubah mode cache dengan Cloud CDN. Mode cache memungkinkan Anda mengonfigurasi cara Cloud CDN meng-cache konten Anda.
Di Backend configuration, pilih backend, lalu klik Editedit.
Pastikan Enable Cloud CDN dipilih.
Di bagian Cache mode, pilih salah satu opsi berikut:
Menyimpan konten statis dalam cache (direkomendasikan): Konten statis adalah aset web yang tidak berubah untuk setiap pengguna. Konten statis
berdasarkan Content-Type dalam respons. Untuk mengetahui informasi selengkapnya, lihat
konten statis.
Gunakan setelan origin berdasarkan header Cache-Control: Menyimpan respons cache dengan perintah cache yang valid di header respons.
Paksa cache semua konten: Menyimpan dalam cache semua konten yang berhasil ditayangkan oleh
asal, mengabaikan perintah private atau no-store.
Ganti CACHE_MODE dengan salah satu dari berikut ini:
CACHE_ALL_STATIC (default): Otomatis meng-cache konten statis. Respons yang
ditandai sebagai tidak dapat di-cache (perintah private atau no-store di
header respons Cache-Control) tidak di-cache. Untuk menyimpan konten dinamis dalam cache, konten harus memiliki header penyimpanan dalam cache yang valid.
USE_ORIGIN_HEADERS: Mewajibkan asal untuk menetapkan
header penyimpanan dalam cache yang valid untuk
menyimpan konten dalam cache. Respons tanpa header ini tidak di-cache di edge Google
dan memerlukan perjalanan penuh ke origin pada setiap permintaan, yang berpotensi
memengaruhi performa dan meningkatkan beban pada server origin.
FORCE_CACHE_ALL: Menyimpan semua konten dalam cache (yaitu, respons yang berhasil),
mengabaikan perintah private atau no-store di header respons
Cache-Control. Hal ini dapat menyebabkan penyimpanan konten pribadi per pengguna (dapat diidentifikasi pengguna) ke dalam cache. Hanya aktifkan ini di backend yang tidak menayangkan konten pribadi atau dinamis, seperti bucket Cloud Storage. Jangan aktifkan ini di backend yang menayangkan konten pribadi atau dinamis.
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
Tambahkan cuplikan berikut ke isi permintaan JSON:
USE_ORIGIN_HEADERS: Mewajibkan origin menetapkan header cache
yang valid untuk
menyimpan konten dalam cache. Respons tanpa header ini tidak di-cache di edge Google
dan memerlukan perjalanan penuh ke origin pada setiap permintaan, yang berpotensi
memengaruhi performa dan meningkatkan beban pada server origin.
FORCE_CACHE_ALL: Menyimpan semua konten dalam cache (yaitu, respons yang berhasil),
mengabaikan perintah private atau no-store di header respons
Cache-Control. Hal ini dapat menyebabkan penyimpanan konten pribadi per pengguna (dapat diidentifikasi pengguna) ke dalam cache. Anda hanya boleh mengaktifkan ini di backend yang tidak menyajikan konten pribadi atau dinamis, seperti bucket Cloud Storage.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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."]]