1

I have the following endpoints:

  • /orders
  • /orders?status=open
  • /orders?status=open&my_orders=true

The third example uses headers to determine user and return their specific items.

Obviously, this is a poor API design but we want to cache the first two and not the third. The caching policy can be modified to either whitelist or exclude querystring params but based on my understanding this won't be helpful. If we include the user specific header than the first 2 URIs will all be cached per user.

Is there an option I am missing that allows me to avoid caching the 3rd endpoint, while still caching the first two? Another option is to cache the 3rd but include the user specific headers in the cache key.

1 Answer 1

2

If you exclude the my_orders query string from the cache policy, CloudFront will not include that value in the cache key. That means all else held equal, these two URI paths will share the same cache key:

  • /orders?status=open
  • /orders?status=open&my_orders=true

That doesn't sound like it's what you want - you do want to treat requests with my_orders=true as separate cache keys, but you also need to account for a specific request header where the value of that header changes the cache key. If that's the case, you need to include the request header as part of your cache key (which will also ensure CloudFront passes it through to your origin)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.