从云端发送 "Cache-Control : no-cache"

Sending "Cache-Control : no-cache" from cloudfront

我有一个文件,存储在 S3 上,假设 index.html 不时更改。

我不希望最终客户缓存它,所以我想发送一个 http header max-age=0, no-store, no-cache, must-revalidate.

据我从文档中了解到,如果我在 S3 元数据中设置此 header,Cloudfront 将遵守此 header,这意味着 Cloudfront 将始终为每个请求重新读取文件。

我不希望 Cloudfront 这样做,我很乐意在文件更改时使 Cloudfront 失效。

这可能吗?

if I set this header in S3 metadata, Cloudfront will respect this header, which means Cloudfront will always reread the file for each request.

这是不正确的。

当 CloudFront 中的 Minimum TTL 设置大于 max-ages-maxage 时,或者当原始响应包含 no-cacheno-store 中的任何一个时, and/or private 指令,CloudFront 仍存储对象达到最小 TTL。

这就是它被称为 "minimum" TTL 的原因。 CloudFront 假定 TTL 短于此(如这些指令所示)的对象仍应被缓存——只是不长于最小 TTL。因此,如果这是一个较大的值,则对 S3 的请求数将最少。

Specifying How Long Objects Stay in a CloudFront Edge Cache (Expiration)