What is HTTP caching; what does the Cache-Control header do?
Short answer
HTTP caching is storing the responses to repeated requests and serving them from an intermediate layer or from the browser without going to the origin; it reduces the server's load and the response time. Whether a response can be stored and how long it stays valid are specified by the Cache-Control (such as max-age, no-store, private), Expires and Pragma headers. In TR7, caching is done with the Cache profile assigned to the HTTP vService in the Cache field, and it works only for the requests that match the Caching Rules condition (the default rule is the common static file extensions). TR7 first looks for the request in the cache; if it finds it (HIT), it responds without going to the Backend Service; if it does not (MISS), it forwards the request and stores a suitable response for the Cache Timeout period (default 1 hour). By default, it follows the Backend Service's cache headers; Ignore Response Headers ignores them. The header in the Cached(HIT) Header Name field (default TRCACHE) is added to every response with the value HIT or MISS.
Where It Is Used in TR7
| Where | Field / label | What for |
|---|---|---|
| Load Balancer → Profiles (L4-L7 Behavior Sets) → Cache | Caching Rules | Which requests are cached; the default rule is that the path ends with the common static file extensions |
| Same profile | Cache Timeout (default 1 hour), Max. Object Size (MB) | The storage time and the largest response that can be stored |
| Same profile | Ignore Response Headers, Ignore Request Headers (both off by default) | Ignoring the cache headers of the Backend Service or of the client |
| Same profile | Ignore HTTP Method Standards (off by default) | Caching methods other than GET and HEAD too |
| Same profile | Ignore Host Header, Ignore Query, Dynamic Caching | Which information the cache key is made up of |
| Same profile | Cached(HIT) Header Name (default TRCACHE) | Showing whether the response came from the cache (HIT) or from the Backend Service (MISS) |
| HTTP vService form → Details | Cache | Assigning the Cache profile to the vService |
| Load Balancer → Load Balancer vService List → vService → Dashboard | Frontend Cache, Frontend Cache Hit Ratio | The number of requests looked up in the cache and served from the cache, and the HIT ratio; the panel is visible only if a Cache profile is assigned to the vService |
Common Misconceptions
- "Once a Cache profile is assigned, all responses are cached." Only the requests that match the Caching Rules condition are looked up in the cache and stored; the Backend Service's directives such as
Cache-Control: no-storeorprivateapply unless Ignore Response Headers is turned on. - "The TRCACHE header is present only in a response that comes from the cache." The header is added to every response; its value is HIT in a response served without going to the Backend Service, and MISS in a response that comes from the Backend Service. Details: How do I know a response came from the cache (Cached(HIT) Header Name, default value TRCACHE)?
- "User-specific pages can also be cached safely." Responses that carry session content are left out of Caching Rules, and Ignore Response Headers is not turned on for these responses: How do I prevent user-specific content from being cached by mistake?
How it is done in the documentation
Related questions
