1

Background

I have an EC2 instance serving Websocket connections, with CloudFront over the top. Now I am serving dynamic content that cannot be cached within CloudFront so I've effectively disabled object caching by setting the "Cache Based on Selected Request Headers" option to "All".

I also need to handle query strings, so I had to mess with the "Query String Forwarding and Caching" option.

Question

My question is basically the title:
Can I make CloudFront forward all query strings, but cache based on none?
It seems I have three different options, and none of them do that, but I might be missing something.
For now, I've set the option to "Forward all, cache based on all".

Disclaimer

I don't actually know if what happens at the moment affects my application in any way (it doesn't seem to). Hopefully though, after reading some answers I can understand what's being cached as a result of that option being selected.

Dimos
  • 13
  • 1
  • 4

1 Answers1

3

I believe you are misinterpreting the meaning of Forward all, cache based on all, which is not very clearly worded. It oversimplifies or perhaps even misrepresents what the option actually does.

Selecting this doesn't enable caching or cause more caching. In fact, it causes less caching. This option adds any/all the query string parameters to the cache key, which in turn means that any two requests with exactly the same path, exactly the same whitelisted headers but different query string parameter keys and/or values are considered to be unrelated requests for two different objects, thus even if the first request results in a response being cached, the second request will not use that cached response.

A better phasing might be forward all, and potentially serve objects from cache only when all are identical. but Rhat still leaves something to be desired, I suspect, but perhaps it clarifies things somewhat.

If all headers are whitelisted for forwarding, nothing will be cached, regardless of this setting. The same holds true if your Cache-Control headers from the origin direct CloudFront not to cache the object. Since nothing is cached, "cache based on all" has no impact and CloudFront will do what you intend, here.

Michael - sqlbot
  • 22,658
  • 2
  • 63
  • 86
  • Perfect, thank you. That's what I wanted to hear. "If all headers are whitelisted for forwarding, nothing will be cached, regardless of this setting" That was my assumption as well, and I was looking for some confirmation from the docks, but didnt find it. Good to know :) – Dimos Apr 17 '20 at 11:00