Stay organized with collections Save and categorize content based on your preferences.
This page discusses the options you have to control how your Cloud Storage objects are cached. This page focuses on the Cloud Storage built-in cache and Cloud CDN, but Cloud Storage is also compatible with third-party CDNs.
OverviewWhen a Cloud Storage object is cached, copies of the object data are stored in a Google or internet cache so your object can be served faster in future requests. While caching can improve performance, you also risk serving stale content if you make updates to your object but a cache continues to serve the earlier version of the object.
Built-in caching for Cloud StorageCloud Storage can behave like a Content Delivery Network (CDN) with no work on your part, because an object's data is cached in the Cloud Storage network if its Cache-Control
metadata is set to allow caching and the following criteria are met:
Cache-Control
metadata. Additionally, depending on the network path, once object data has left Cloud Storage, the Cache-Control
value associated with it might be overwritten, for example by a CDN that the data passes through.
Cloud Storage respects standard values for Cache-Control
, such as the following:
public
: the object can be cached.
private
: the object won't be cached by Cloud Storage, but can be cached in a requester's local cache.
no-cache
: the object can be cached, but cannot be used to satisfy future requests unless first validated by Cloud Storage.
no-store
: the object can't be cached.
max-age=TIME_IN_SECONDS
: the length of time an object can be cached before it's considered stale. You can set max-age
to any length of time. Stale objects are not served from caches, except in special circumstances.
To set the Cache-Control
metadata for an object, see Editing object metadata.
When there's an organization-level IAM Deny policy that restricts read access for an object from the principal identifier allUsers
, built-in caching is disabled for the object, even if there's a bucket-level IAM policy that grants read access for the object to allUsers
. However, if the IAM Deny policy only restricts individual users, built-in caching remains enabled for the object.
Performance can be much better for publicly cacheable objects. If you have an object being used to control many clients and thus want to disable caching to provide the latest data:
Consider instead setting the object's Cache-Control
metadata to public
with max-age
of 15-60 seconds. Most applications can tolerate having an object be out of date for a few seconds, in exchange for performance improvements.
Use Cache-Control: no-store
for an object to indicate that the object must not be cached for subsequent requests in any cache.
Anywhere Cache is a fully-managed, always consistent Cloud Storage feature that lets you create caches in the same zone as your workloads. The caches can then be used to complete data read requests instead of your multi-region bucket, helping you control storage costs while running large, data-intensive workloads that would otherwise incur multi-region data transfer fees and impact performance. To learn more about Anywhere Cache, its benefits, and when you should use this feature, see Anywhere Cache overview.
Cloud Storage with Cloud CDNFor the best performance when delivering content to users, we recommend using Cloud Storage with Cloud CDN.
To use Cloud CDN, you must use an external Application Load Balancer with your Cloud Storage buckets as a backend. For a tutorial on setting up an HTTP(S) load balancer with a Cloud Storage bucket, see Hosting a static website.
Cloud CDN cache modes allow you to apply a unified caching configuration across all your objects. Cloud CDN uses the Cache-Control
metadata set on your objects to determine how they should be cached, unless you override the Cache-Control
metadata using a cache mode or TTL limit.
When choosing between Cloud Storage built-in caching and Cloud CDN, consider the following:
Feature Cloud Storage Cloud CDN Max cacheable file size 10 MiB 100 GiB 1 Default cache expiration 1 hour 1 hour (configurable) Support for custom domains over HTTPS No Yes Cache invalidation No Yes1The maximum cacheable file size for Cloud CDN is 100 GiB if the origin server supports byte range requests. If the origin server doesn't support byte range requests, the maximum cacheable file size for Cloud CDN is 10 MiB.
Pricing considerationsIn terms of pricing, the choice between Cloud Storage built-in caching and Cloud CDN depends on how much data you serve every month, which determines the amount of networking costs you incur.
If you serve less than a few GiB of cacheable data a month, it may be cheaper overall for you to rely on Cloud Storage built-in caching. Cloud Storage caching may incur higher networking costs than Cloud CDN, since cached and uncached objects are charged the same outbound data transfer cost (which means you pay full price for cache hits). However, you only pay for data storage and operations usage costs associated with Cloud Storage, instead of the combination of Cloud Storage, Cloud CDN, and Cloud Load Balancing.
If you regularly serve 100 GiB or more of cacheable data a month, or need to use per-request logging and custom headers, it may be cheaper overall for you to rely on Cloud CDN. You incur Cloud Storage outbound data transfer and Cloud CDN cache fill costs for cache fill, and Cloud CDN networking prices apply after the cache is full. The networking cost savings you gain from using Cloud CDN may be worth the higher operating costs associated with maintaining the external Application Load Balancer and Cloud CDN along with Cloud Storage.
Cache-Control
metadata.Cache-Control
directives.Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["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-08-07 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4