设置CloudFront图像带查询字符串的缓存生存时间。

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

set cache ttl for cloudfront images with query string

问题

我正在使用S3和CloudFront来传递静态内容。唯一的问题是在使用查询字符串时出现的图像缓存TTL问题。

例如

https://cloudfronturl/static_images/banners/web/Slider-1.jpeg?format=auto

对于这个问题,我遇到了

使用高效的缓存策略提供静态资产

我已经在CloudFront中设置了缓存策略,如果我不使用查询字符串请求,它就会起作用

例如

https://cloudfronturl/static_images/banners/web/Slider-1.jpeg

我该如何解决缓存问题。查询字符串是必需的,因为我希望在不同的地方以不同的格式和大小获取图像。

英文:

I am using S3 with cloudfront to deliver the static content. The only issue is with images cache TTL when I use query string in my images.

For example

https://cloudfronturl/static_images/banners/web/Slider-1.jpeg?format=auto

For this I am getting issue of

> Serve static assets with an efficient cache policy

I have already setup cache policy in my cloudfront and it is working if I request without query string

for example

https://cloudfronturl/static_images/banners/web/Slider-1.jpeg

How can I fix the cache issue. Query string is required because I want images in different format and size for different place

答案1

得分: 1

以下是您要翻译的内容:

  • 不转发查询字符串到源站。如果您不转发查询字符串,CloudFront 将不会根据查询字符串参数进行缓存。

  • 转发查询字符串到源站,并根据查询字符串中的所有参数进行缓存。

  • 转发查询字符串到源站,并根据查询字符串中指定的参数进行缓存。

您还可以尝试通过添加自定义标头到缓存策略来进行缓存控制,使用 cache-control 标头。您可以参考此链接:https://i.imgur.com/rvzgDkh.png

更多信息请参考:https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/QueryStringParameters.html

英文:

There are few options in Cloudfront for whitelisting or allowing/blocking queryStrings to optimize cache.

  • Don't forward query strings to the origin at all. If you don't
    forward query strings, CloudFront doesn't cache based on the query string
    parameters.

  • Forward query strings to the origin, and cache based on all
    parameters in the query string.

  • Forward query strings to the origin, and cache based on specified
    parameters in the query string

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/QueryStringParameters.html

If the above doesn't work you can try adding a new custom header to cache policy with cache-contorl header https://i.imgur.com/rvzgDkh.png

huangapple
  • 本文由 发表于 2023年5月14日 22:06:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247883.html
匿名

发表评论

匿名网友

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

确定