使用随CloudFront分发的Cache-Control标头从s3提供的图像不缓存?

时间:2017-08-25 15:02:42

标签: amazon-web-services caching amazon-s3 amazon-cloudfront

我正在从S3存储桶提供静态图像,并向存储桶中的所有资产添加protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*...*/ interceptExternalIntentAndPlaySongFromUri(getIntent()); } @Override protected void onNewIntent(Intent intent) { interceptExternalIntentAndPlaySongFromUri(intent); } private boolean interceptExternalIntentAndPlaySongFromUri(Intent intent){ Uri data = intent.getData(); if (data != null && intent.getAction() != null && intent.getAction().equals(Intent.ACTION_VIEW)){ String scheme = data.getScheme(); String filename = ""; if ("file".equals(scheme)) { filename = data.getPath(); } else { filename = data.toString(); } player.setDataSource(filename); setIntent(new Intent()); //this is to remove the last intent //without the above line, last request is reloaded when the user open another app //and return in this return true; //has intercepted an external intent } return false; //has not intent to intercept } 标头。然后通过cloudfront分发资产。以下是浏览器中的标题:

    @v1(column for 1s table) = '1,2,3,4'
    @v2(column for 2nd table) = '1,2,3,4,5,6,7'

我不确定该如何解决这个问题。我相信Cache-Control: public,max-age=31557600意味着边缘服务器正在缓存我的资产。这是否意味着CloudFront已服从S3发送的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== 标头,这些图像是否正在缓存在CloudFront边缘服务器中?或者图像被缓存在broswer中?我很感激任何帮助,以澄清我的困惑。谢谢!

1 个答案:

答案 0 :(得分:2)

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

  • 命中均值来自缓存。如果你看到小姐,那就去了原点
  • 年龄,对象在缓存中的秒数。

基于那些头文件,是的,cloudfront通过设置缓存控制头来缓存您的内容。