亚马逊S3:Cache-Control和到期日的区别,并设置槽REST API亚马逊、到期日、区别、Control

2023-09-11 09:12:07 作者:呐年旧时光

我想提高我的网站加载速度,所以我用 http://gtmetrix.com/ ,以检查我能得到改善。其中最低的等级,我得到了充分利用浏览器缓存。我发现,我的文件(主要是图片),有问题的过期未指定。

I want to enhance my sites loading speed, so I use http://gtmetrix.com/, to check what I could improve. One of the lowest rating I get for "Leverage browser caching". I found, that my files (mainly images), have problem "expiration not specified".

好了,问题是清楚的,我想。我开始google搜索,我发现,超过有效期限的Amazon S3 preFER缓存控制元数据(我失去了这个链接,现在我想也许我误解的东西)。无论如何,我开始寻找如何缓存控制元添加到S3对象。我发现 这个页面:http://www.bucketexplorer.com/documentation/amazon-s3--how-to-set-cache-control-header-for-s3-object.html

Okay, problem is clear, I thought. I start to googling and I found that amazon S3 prefer Cache-Control meta data over Expiry date (I lost this link, now I think maybe I misunderstood something). Anyway, I start looking for how to add cache-control meta to S3 object. I found this page: http://www.bucketexplorer.com/documentation/amazon-s3--how-to-set-cache-control-header-for-s3-object.html

我才知道,我必须添加字符串到我的PUT查询。

I learned, that I must add string to my PUT query.

X-AMZ-元缓存控制:最大年龄=<在几秒钟&GT值; //(有等号和数字之间没有必要的空间(我在这里犯了一个错误))。

x-amz-meta-Cache-Control : max-age= <value in seconds> //(there is no need space between equal sign and digits(I made a mistake here)).

我用建:缓存控制:最大年龄= 1296000 和它的工作好了。

I use construction: Cache-control:max-age=1296000 and it work okay.

在我读 https://developers.google.com/speed/docs/best-practices/caching 这篇文章告诉我:1)设置过期时间为最短1个月,和preferably长达一年,在未来。

After that I read https://developers.google.com/speed/docs/best-practices/caching This article told me: 1) "Set Expires to a minimum of one month, and preferably up to one year, in the future."

2)我们preFER会过期的Cache-Control:max-age的,因为它是在更广泛的支持(建议在主题)。

2) "We prefer Expires over Cache-Control: max-age because it is is more widely supported."(in Recommendations topic).

于是,我开始寻找方法来设置日期S3对象到期。 我发现这一点: http://www.bucketexplorer.com/documentation/amazon-s3--set-object-expiration-on-amazon-s3-objects-put-get-delete-bucket-lifecycle.html

So, I start to look way to set Expiry date to S3 object. I found this: http://www.bucketexplorer.com/documentation/amazon-s3--set-object-expiration-on-amazon-s3-objects-put-get-delete-bucket-lifecycle.html

和我找到了什么:使用Amazon S3的对象生命周期管理,您可以定义在Amazon S3对象的对象过期曾经为S3对象定义的生命周期到期后,亚马逊的S3将删除这些对象,所以,当你想继续S3的数据只在有限的时间,你希望它自动被Amazon S3的删除,可以设置对象过期。

And what I found: "Using Amazon S3 Object Lifecycle Management , you can define the Object Expiration on Amazon S3 Objects . Once the Lifecycle defined for the S3 Object expires, Amazon S3 will delete such Objects. So, when you want to keep your data on S3 for a limited time only and you want it to be deleted automatically by Amazon S3, you can set Object Expiration."

我不想从S3中删除我的文件。我只想补充缓存元的最大缓存时间和/或文件到期时间。

I don't want to delete my files from S3. I just want add cache meta for maximum cache time or/and file expiry time.

我完全糊涂了这一点。有人可以解释我一定要用什么:?对象期满或缓存控制

I completely confused with this. Can somebody explain what I must use: object expiration or cache-control?

推荐答案

您的文件不会被删除,只在到期日以后不被缓存。

Your files won't be deleted, just not cached after the expiration date.

亚马逊的文档说:

截止日期和时间在到期后的头通过,CloudFront的每一个边缘位置接收为对象的请求时再次获取对象从源服务器。

After the expiration date and time in the Expires header passes, CloudFront gets the object again from the origin server every time an edge location receives a request for the object.

我们建议您使用的Cache-Control max-age的指令,而不是Expires头字段控制对象缓存。如果同时指定了缓存控制最大年龄和过期值,CloudFront的使用最大年龄仅值。

We recommend that you use the Cache-Control max-age directive instead of the Expires header field to control object caching. If you specify values both for Cache-Control max-age and for Expires, CloudFront uses only the value of max-age.