如何在Cloudfront中存储经常变化的静态文件?

huangapple go评论72阅读模式
英文:

How to store frequently changing static files in Cloudfront?

问题

我有一些静态图像文件,我们在广告活动中使用这些文件。问题是营销团队经常更改这些文件,而且它们需要时间才能在 CloudFront 缓存中更新。CloudFront 是存储此类文件的最佳位置吗?如果是的,我该如何处理,以确保提供更新的文件。
如果 CloudFront 不是最佳解决方案,那么我应该使用什么服务?Origin 到 CloudFront 是一个 S3 服务器。

英文:

I have some static image files that we use for our campaigns. The problem is that the marketing team changes the files very frequently and they take time to update in cloudfront cache.<br> Is cloudfront the best place to store such files? If yes, how do I go about handling this and make sure updated files are served.
If instead cloudfront is not the best solution then what service should I use? <br>Origin to cloudfront is an s3 server.

答案1

得分: 1

这取决于这些文件更新的频率以及CloudFront的其他好处是否值得。

如果这些文件平均每小时更新一次或更频繁,而且您在全球范围内有数千或数百万的用户,那么CloudFront仍然是有益的,因为这些用户将由于缓存而减少加载时间。可以使用对象版本控制(参见这里)或者设置一个较低的TTL,低于您允许文件过时的时间 - 按照每小时更新一次的示例,您可以将TTL设置为15-30分钟。

如果您的所有用户都在类似的位置,那么只需直接在该位置使用S3存储桶。这样可以节省CloudFront的费用,并且缓存与您的用例不太匹配。

您还可以使用缓存失效,但这会额外产生成本,如果您不得不经常这样做,那么您应该减少TTL或者迁出CloudFront。

英文:

It depends how often these files are updated and whether the other benefits of CloudFront make it worth it.

If the files are updated on average, say, once an hour or more, and you have thousands or millions of users scattered around the world, then CloudFront is still beneficial, since those users will see reduced load times due to the cache. Either use object versioning (see here) or just set a low TTL, lower than the amount of time you're happy to allow files to be out of date for - going with the updated-once-an-hour example, perhaps you could set a TTL of 15-30 minutes.

If all your users are in a similar location, then just use the S3 bucket directly in that location. You'll save on CloudFront costs and caching didn't align well with your use case anyway.

You can also use cache invalidations, but these cost extra and if you're having to do this too often then you should decrease the TTL or move off CloudFront.

答案2

得分: 1

近期(从2020年8月起)发布在AWS博客上的文章标题为《为什么CloudFront会提供来自Amazon S3的过时内容?》(链接:https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-serving-outdated-content-s3/),讨论了两种解决方案:

  1. 使S3对象失效:您可以使S3对象失效,从而将其从CloudFront分发的缓存中移除。在对象从缓存中移除后,下一个请求将直接从Amazon S3中检索该对象。
  2. 使用对象版本控制:如果您经常更新内容,建议您使用对象版本控制来清除CloudFront分发的缓存。对于频繁的缓存刷新,使用对象版本控制的成本可能比使用失效要低。
英文:

The recent (from August 2020) AWS blog titled Why is CloudFront serving outdated content from Amazon S3? discusses two solution:

  1. Invalidate the S3 objects: You can invalidate an S3 object to remove it from the CloudFront distribution's cache. After the object is removed from the cache, the next request retrieves the object directly from Amazon S3.
  2. Use object versioning: If you update content frequently, we recommend that you use object versioning to clear the CloudFront distribution's cache. For frequent cache refreshes, using object versioning might cost less than using invalidations.

huangapple
  • 本文由 发表于 2020年10月8日 20:20:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/64262393.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定