cachingkeyamazon-cloudfrontaws-policies

Understanding AWS cache key for specific scenario


Imagine the following scenario:

A customer is using AWS CloudFront and is serving a site that expects and ordinarily receives no query strings. Essentially the entire site is static and the CDN is purely enabling performance by caching and distributing the content.

On occasion, we as a solutions provider for the customer, wish to refresh any page (JavaScript) on the customer site and within that refresh request, append a query string with parameter values that will be unique to each visitor. This event will only happen once per visitor in a set period - say for argument's sake, 365 days.

With the existing cache configuration, the cache can be busted and performance affected when x new visitors (x being sizeable) come to the site and trigger the refresh event.

I wish to understand how we can configure the cache key to send any page request with our query string included, to the origin but not store it in the cache once served. The cache should only store the page when the static URL is requested not the dynamic URL (dynamic because our query string has been included) when it is requested.

Any assistance would be appreciated.


Solution

  • You can specify which query strings to be included in the cache key or not, have a look at this document https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html#cache-policy-query-strings. With include specified query strings cache behaviour cloudfront will send the request to origin with query strings and than you probably want your origin to send cache header as no-cache so cloudfront will not cache.