Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cloudfront/s3 not using cache-control

I am uploading an image to S3. Here are the header/request:

PUT /d899a0475f39e4a1d8c4b2af540d0820.png?AWSAccessKeyId=AKIAIHRUBWYK7YNNWSLQ&Expires=1376548390&Signature=uP677w4lNA81USKByuJwU0FmUuE%3D&Cache-Control:%20max-age=229000 HTTP/1.1
Host: test199801672.s3.amazonaws.com
Content-Length: 436983
Content-Type: image/png

I am passing in Cache-Control: max-age=229000

I get a 200 OK response and the image is uploaded, but for some reason the Cache-Control value isn't read. When downloading the image, I get:

HTTP/1.1 200 OK
Content-Type: image/png
Content-Length: 436983
Connection: keep-alive
Date: Thu, 15 Aug 2013 05:33:15 GMT
Last-Modified: Thu, 15 Aug 2013 05:33:11 GMT
ETag: "dbb3afa053cfc18e45f1d8c7ef8ddfd4"
Accept-Ranges: bytes
Server: AmazonS3
Via: 1.0 9dd1962ecf68cae08454f386dd1975c1.cloudfront.net (CloudFront)
X-Cache: Miss from cloudfront
X-Amz-Cf-Id: anyUV_WtyIdEjDrRsrsWc5l9WGIVW0AnIjNn7b_g_EgS7rlP0rxoAw==

No Cache-Control header in response. X-Cache says: Miss from cloudfront

What am I doing wrong? Thanks!

like image 790
0xSina Avatar asked Jun 03 '26 05:06

0xSina


1 Answers

It works for me.

I have set the Cache-Control max-age=3600 header for each of my files in S3 using the control panel under metadata. (API can do this)

My CloudFront is has the Behavior Object Caching = Use Origin Cache Headers.

My website's header responses now show the Cache-Control header I set in S3.

(of course had to wait cloud front to invalidate its existing verison of those files, I helped this along with CloudFront invalidation on those files)

like image 89
David Valentiate Avatar answered Jun 07 '26 23:06

David Valentiate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!