Are the query string and Host Header part of the cache key; can I change this?
Short answer
Yes, both are included; the default cache key is Host + path + query string. If Ignore Host Header is turned on in the Cache profile, Host is removed from the key, and if Ignore Query is turned on, the query string is removed from it. If Dynamic Caching is turned on, the values selected in the Key list (e.g. language or cookie) are added to the end of the key.
How Does It Work?
The cache compares the key of the incoming request with the keys of the previously stored copies; if the key is the same, the stored response is served. When a part is removed from the key, requests that differ in that part share the same copy.
| Setting | Key | Example: requests that get the same copy |
|---|---|---|
| Default | Host + path + query string | Only the exact same address |
| Ignore Host Header on | Path + query string | www.example.com/logo.png and cdn.example.com/logo.png |
| Ignore query on | Host + path | /app.css?v=1 and /app.css?v=2 |
| Both on | Path | The same path with a different domain name and query string |
| Dynamic caching on | The key above + Key values | The same address and the same Key values |
The HTTP method, cookies and headers such as Accept-Language are not in the default key; if needed, they are added with Dynamic caching (What is Dynamic Caching, and when should it be used?).
The Cache Key in TR7
- Where: Load Balancer → Profiles → Cache → right-click on the profile row → Edit → the Ignore Host Header and/or Ignore Query switch is turned on → Save. Both options are off by default.
- Effect of the change: The save is applied without dropping open connections; the copies in the cache are deleted (recommended values). If the profile is used in more than one vService, the change is reflected in all of them (Used in tab). In a cluster, it is also sent to the peer device with the default auto-sync; if Manual Sync Mode is on, it is sent with Synchronize.
- WEB-CLI: The
lb cache update id <id> --ignoreQuery trueand--ignoreHost truefields are used (fields that relax the matching criterion). - Verification: While Ignore query is off, when
curl -s -o /dev/null -D - "https://www.example.com/app.css?v=1"and then?v=2are requested, the second request getsTRCACHE: MISS; while it is on, it getsTRCACHE: HIT. - When it is turned on: Ignore query only if static files that do not depend on the query string are cached; Ignore Host Header only if more than one domain name serves the same content.
Common Misconceptions
- "Ignore query only increases the hit ratio." Different query strings get the same response; on dynamic pages such as
?id=1and?id=2, wrong content is served. - "
?v=2always refreshes the cache." While Ignore query is on, the version parameter is not included in the key and the old copy continues to be served (Old content is still being served after an application update; what should I do?). - "Dynamic caching replaces the key." The selected values are added to the end of the URL, not in its place.
- "Ignore request headers and Ignore response headers also change the key." These two options affect not the key but the check of whether the request and the response are suitable for caching.
How it is done in the documentation
