2

I have recently setup a Cloudfront distribution with the following behaviour cache policy:

  • TTL settings:
    • Minimum TTL (seconds): 0
    • Maximum TTL (seconds): 31536000
    • Default TTL (seconds): 0
  • Cache Keys:
    • Headers - None
    • Cookies - None
    • Query strings - All

Unfortunately pages with no-cache response headers continue to cache the response at fairly low levels of concurrency. I used apachebench to run 100 requests with concurrency of 5, and received the following:

    100 Cache-Control: no-cache, no-store, must-revalidate, max-age=0
     25 X-Cache: Hit from cloudfront
     75 X-Cache: Miss from cloudfront

I also captured what should be unique response headers that should be unique per request/response (given there are no request headers/cookies) and this also shows that there are duplicate Set-Cookie responses. For example, this response came back 4 times:

      4 Set-Cookie: csrftoken=h2uU7TKHJ6AicHgOIaJTwC5qIXJN4Zwf; Domain=.mysite.com; expires=Tue, 17-Jan-2023 15:10:37 GMT; Max-Age=31449600; Path=/

I do have ways around this I believe, such as higher priority Cloudfront behaviours to set a no-cache policy, however it takes the power away from the server-side to decide whether a response should dynamically be cached, and indicates that Cloudfront is not honouring the server-side decision.

1
  • Hey, i think this is a similar question on SO which refers to your proxy caching.
    – djdomi
    Jun 14 at 4:17

1 Answer 1

0

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html#ExpirationDownloadDist defines that when the origin responds with Cache-Control: no-cache, no-store, must-revalidate, max-age=0 and the minimum TTL then CloudFront does not cache the response at all.

There is an exception for a cold CDN cache. As I understand it, that special case works differently. When this occurs and the requests are identical (for example, identical query strings and they all have no cookie set), the CloudFront CDN may forward a single request and then fulfil remaining requests using the response from that single forwarded requests.

CloudFront does not honor the HTTP Vary: header here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.