Can I do caching on TR7; what are the default settings?
Short answer
Yes, by assigning a Cache profile on the HTTP vService. When Cache is checked in the Details panel of the vService, the Default Profile takes effect: the TRCACHE header is added to responses, content is stored for 1 hour, and GET/HEAD requests whose path ends with common static file extensions are cached (Caching Rules); Ignore Host Header, Ignore Query, Ignore Request Headers, Ignore Response Headers, Ignore HTTP Method Standards and Dynamic Caching are off. The cache is kept in memory, its total size is not set, and it is emptied when the vService is restarted.
Problem: The Same Static Files Are Requested from the Backend Service Every Time
When files that do not change, such as CSS, images and fonts, are requested again from the Backend Service for every visitor, the server load and the response time increase unnecessarily. These responses can be stored in memory on TR7 and served to subsequent requests without going to the Backend Service.
Solution: Three Methods
The cache is used only on the HTTP vService; it is not available on the L7 TCP and Network vServices or in SSL passthrough setups where the content is not decrypted on TR7. The values of the default profile:
| Field | Default profile |
|---|---|
| Cached(HIT) Header Name | TRCACHE (HIT in a response from the cache, MISS in one from the Backend Service) |
| Max. Object Size (MB) | Empty (Automatic) |
| Cache Timeout | 1 hours |
| Caching Rules | Requests whose path ends with .txt .bmp .jpeg .pdf .ps .ttf .jpg .svg .webp .css .svgz .woff .csv .gif .mid .png .swf .woff2 .doc .midi .ppt .tif .xls .docx .pptx .tiff .xlsx .mp4 .flv .mov .wmv .avi .ogg .mkv .mpg; .js, .html and .json are not in the list |
| Ignore Host Header · Ignore query · Ignore Request Headers · Ignore Response Headers · Ignore HTTP Method Standards | Off (GET/HEAD only; the cache headers of the Backend Service are taken into account) |
| Dynamic Caching | Off |
The total cache size is not set from a separate field; it is determined automatically according to the Memory Limit value in the QOS section of the vService (HTTP vService · Cache).
| Your situation | Suitable method |
|---|---|
| Turning it on right away with the default settings | Method 1: Cache + Default profile on the vService |
| The duration, rules or header name will be different | Method 2: Custom Cache profile |
| From the command line | Method 3: WEB-CLI |
Method 1: Cache + Default Profile on the vService Recommended
- How it works When Cache is checked on the vService, the Default profile is assigned and caching starts with the values above.
- Where it is openedLoad Balancer → Load Balancer vService List → Edit → Details → Cache
- Requirement None
- vService type HTTP
Step-by-Step Configuration
On the Load Balancer → Load Balancer vService List screen, the HTTP vService is selected and Edit is clicked (How to add to a vService).
Save is clicked. The change is applied without dropping open connections; the progress is followed on the sync indicator at the bottom right of the screen. 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. The cache is in each device's own memory; it is not shared between peer devices.
Verification
curl -s -o /dev/null -D - https://www.example.com/css/site.css is run twice.
TRCACHE: MISS the first time · TRCACHE: HIT the second timeThe Frontend Cache and Frontend Cache Hit Ratio panels on the HTTP Frontend tab of the vService dashboard are checked.
Cache Lookups and Cache Hits increaseMethod 2: Custom Cache Profile
- How it works The duration, rules, header name and ignore options are defined in a separate profile and selected on the vService; the same profile can be used on more than one vService.
- Where it is openedLoad Balancer → Profiles → Cache → Add
- Requirement None
- vService type HTTP
Step-by-Step Configuration
Load Balancer → Profiles → Cache → Add is clicked (How to add).
Name is entered; Cache Timeout (unit seconds / minutes / hours), Caching Rules and, if needed, the other fields are set (profile add form). Rule details: Which content gets cached; how do I define cache rules?
Add is clicked.
The vService is opened with Edit; Details → Cache is checked and the profile is selected from the list. The profile can also be created from the vService form, with Add in the Cache row.
Save is clicked.
Verification
The Cache & Compression row in the Load Balancer Management tab of the vService is checked.
Responses are cached with the … profileMethod 3: WEB-CLI
- How it works The Default profile or an existing profile is written to the Cache field of the vService with a WEB-CLI command.
- Where it is opened TR7 WEB-CLI →
lb service - Requirement WEB-CLI access
- vService type HTTP
Step-by-Step Configuration
The value is default for the Default profile and the name of the profile for a custom profile:
lb service update id <vService> --cache defaultVerification
The cache field in the lb service show <vService> output is checked.
default in the Cache fieldCommon Mistakes
- Looking for the cache on the L7 TCP vService. Cache is found only on the HTTP vService; in SSL passthrough, it cannot be used because the content is not decrypted on TR7 (What is SSL passthrough; when should I use passthrough instead of termination?).
- Assuming that JavaScript and HTML files are cached by default.
.js,.htmland.jsonare not in the default list; if needed, they are added to the rule with a condition. - Assuming that the cache is persistent. The cache is kept in memory; it is emptied when the vService is restarted (e.g. on Reload or on a setting change that requires a restart).
- Blaming the TR7 cache when there is no TRCACHE header. If the header does not appear at all, the Cache profile is not active on the vService or the response came from the browser's own cache (How do I know a response came from the cache (Cached(HIT) Header Name, default value TRCACHE)?).
How it is done in the documentation
