Caching at the edge
Edge caching stores responses on servers physically close to users, often in a content delivery network. A request that hits the cache is served from nearby without ever reaching your origin, which makes it faster and takes load off your servers.
The cache key
The cache key is what the cache uses to decide whether two requests are the same. By default it is the URL. But many responses depend on more than the URL.
- If content varies by language, the accept language header belongs in the key.
- If responses differ for logged in users, an auth dimension belongs in the key.
- Leaving out a dimension serves the wrong content to someone.
Beware over keying
Adding too many dimensions, like a unique session id, makes every request unique so nothing is ever shared. The cache hit rate collapses. Choose the smallest set of dimensions that still keeps responses correct.
Key idea
Edge caching serves responses near users, and the cache key must include every dimension that changes the response while excluding ones that needlessly fragment the cache.