Why are two requests with different clients from the same computer cache misses on cloudfront?

旧街凉风 提交于 2019-12-08 05:57:54

问题


My website uses cloudfront for its images. If I load a webpage in a browser, and then use curl to request an image on that page, then the request with curl is a cache miss. A subsequent request with curl is a cache hit.

example: run this twice:

curl --verbose https://d1hvwudqvjuczb.cloudfront.net/assets/landing/splash_dickenko-2199af423f275d0784c1813cbaab5645.jpg`

The first time, X-Cache will be "Miss from cloudfront", the second time it will be "Hit from cloudfront".

So it seems cloudfront is using some aspect of the request to decide if it should refetch the image or not.

What could this criteria be?


回答1:


The reason you are seeing this behavior is because your requests are different. To give you some background, Cloudfront cache varys based on the http accept-encoding header. In your first example, in your browser, you are sending the value of gzip. With your curl example, by default, you are not. Therefore Cloudfront see's this objects as being unique.

Try passing the --compressed flag in curl and see if the behavior matches your browser.

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html#CompressedCustomOrigin



来源:https://stackoverflow.com/questions/24292681/why-are-two-requests-with-different-clients-from-the-same-computer-cache-misses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!