Variables used as cache key
I’ve a REST API where the response for a single endpoint vary on 3 headers:
- X-Version | Proprietary header | Has values like
3.1.0
,3.2.7
etc - X-Currency | Proprietary header | Has values like
EUR
,USD
etc - Accept-Language | Has value like
it-IT
,en-GB
Questions:
- Are the 2 proprietary keys above considered by default in the cache key or do I have to setup something ?
- Is it possible, given an endpoint, to invalidate only the cached version for a specific combination of 'X-Version
-
X-Currency-
Accept-Language` ? - Which are the default variables used to create a cache key ? Seems to me that the
User-Agent
is used to calculate the cache key but I don’t want this. Can I specify the list of HTTP headers to consider ?
Thanks
–
Simone
-
Hi-
By default, Fastly uses req.http.host, req.url and a generation tag (to facilitate purge_all) as the cache key.
you can add a Vary: on those headers if you want to be able to purge all of the variants in one shot, but otherwise you could add those different attributes to the cache key. You would have to purge using those attributes as well then and I would encourage exploring surrogate-keys for purging as a strategy. Doc on manipulating the cache key is here: https://docs.fastly.com/guides/vcl/manipulating-the-cache-key
Please sign in to leave a comment.
Comments
1 comment