使用 CloudFront 分发的 Cache-Control header 提供来自 s3 的图像不缓存?

Serving images from s3 with Cache-Control header distributed with CloudFront not caching?

我正在从 S3 存储桶提供静态图像,并将 header 的 Cache-Control: public,max-age=31557600 添加到存储桶中的所有资产。然后通过云端分发资产。这是浏览器中的 headers:

Request URL: cloudfront url here
Request Method:GET
Status Code:304 Not Modified
Remote Address: remote address
Referrer Policy:no-referrer-when-downgrade

Response Headers
HTTP/1.1 304 Not Modified
Connection: keep-alive
Date: Fri, 25 Aug 2017 14:00:27 GMT
ETag: "871e4a2d65f891b79a30b1fdf7622650"
Server: AmazonS3
Age: 52182
X-Cache: Hit from cloudfront
Via: 1.1 f348970492a18bf5c630c5acc86c1ee3.cloudfront.net (CloudFront)
X-Amz-Cf-Id: u35A-l_zhEAMsJSmtLmf4VFIPfBfDLdBqIjdjwfAJSDBcJhxLC7OdA==

我不确定该怎么做。我相信 hit from cloudfront 意味着边缘服务器正在缓存我的资产。这是否意味着 CloudFront 已遵守从 S3 发送的 Cache-Control header,并且这些图像正在缓存在 CloudFront 边缘服务器中?或者图像是否缓存在浏览器中?我感谢任何帮助阐明我的困惑。谢谢!

在确定 cloudfront 是否正在缓存时,有两个 headers 需要查看。

  • 命中意味着是从缓存中提供的。看到miss就去原点
  • 年龄,object 已在缓存中的秒数。

根据 headers 的那些,是的,cloudfront 正在按照您的要求通过设置 cache-control headers.

缓存您的内容