Cache key fragmentation from URL parameters
Key Takeaway
The page cache keys each response on the full URL, so every URL variant for the same content becomes its own cache entry. Keep URLs for the same content identical. Use the same parameter order, put per-shopper or per-position values behind a # (where only client-side code can read them), and ignore meaningless parameters with a feature switch.
The B2C Commerce page cache stores each response under a key built from the full request URL, including the query string. When the same content can be reached through many slightly different URLs, the cache stores many copies of it. The cache hit rate then drops, and the application server computes more responses. Avoiding cache key fragmentation means making sure requests for the same content always use the same URL.
How the page cache key works
The page cache is a key-value store. The cache key is the full URL, including the query string. The value is the cached page. A request served from the page cache puts no load on the application or storage layers.
Any difference in the URL creates a separate cache entry, even when the response is identical. For example, each of these differences creates a different key:
- A changed parameter value, such as
param1=1andparam1=2 - An added parameter
- The same parameters in a different order
- A different domain
- A different path
Each new key starts as a cache miss, so the response must be computed before it can be cached. Too many URL variants for the same content therefore produce a very large number of cache entries and a lower cache hit rate.
A storefront links to the same filtered category page from two places. The header menu builds the URL with ?color=red&size=9. A promotion banner builds it with ?size=9&color=red. Both URLs return the same page, but the page cache sees two keys. The first request through each link is a cache miss that the application server must compute, and the page now takes two cache entries instead of one.
Always build URLs with the same parameter order, because the same parameters in a different order miss the existing cache entry.