What is a cache key?
A cache key is the identifier a cache files a response under, usually the method and URL plus selected headers, cookies or query parameters.
A cache key is the identifier a cache stores a response under and looks it up by. In HTTP it is at least the request method and target URI, and `Vary` adds request headers to it. CDNs let you add or remove parts, such as query parameters, cookies, headers or the device type.
GET https://example.com/pricing?utm_source=mail
key without query string: example.com/pricing
key with query string: example.com/pricing?utm_source=mailEvery distinct key is a separate entry with its own hit or miss. Extra parts in the key, such as tracking parameters, split one page into many entries, and lower the cache hit ratio. Amazon CloudFront's guide to raising the hit ratio recommends forwarding only the query string parameters, cookies and headers the origin actually uses.
- Remove from the key anything that does not change the response.
- Keep in it everything that does, or the cache serves the wrong variant. That includes the language and anything else listed in `Vary`.
- Cache warming fills one key per request, so warm the URL and header combinations your visitors actually use.
Related terms
References
- RFC 9111: HTTP Cachinghttps://www.rfc-editor.org/rfc/rfc9111
- Amazon CloudFront: Control the cache keyhttps://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-the-cache-key.html
- Amazon CloudFront: Increase the proportion of requests served from cacheshttps://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cache-hit-ratio.html
Warm your cache after every deploy
sitewarm requests the pages in your sitemap after a deploy and reports the cache state the CDN returns for each one, with the vantage point it was measured from.