lb cache
The lb cache command creates the cache profiles that manage the responses coming from the backend being kept on TR7. When the profile is bound to a vService, the responses that comply with the rules are kept and are given to the subsequent requests without going to the backend. Its panel equivalent is the Cache screen.
Command Summary
Writing Order
lb cache add web-cache--timeout.val 30 --timeout.unit m --sizeMB 20--cacheRules.0.id …lb service update id <vService> --cache <profile> — only in the vServices of the HTTP type Required Fields
| Order | Field | Status | Value |
|---|---|---|---|
| 1 | name | Required | The name of the profile; it must be unique in the collection |
The rest of the profile is optional: if no field is given, the profile is formed with the defaults.
The Duration, the Size and the Header
| Field | What it does | What is written after it |
|---|---|---|
--timeout.val · --timeout.unit | Determines how long a response will stay in the cache | A number and a unit: s seconds · m minutes · h hours. The default is 1 hour, the shortest is 10 seconds |
--sizeMB | Limits the size of the largest object that will be cached | An integer between 0 and 2048 (MB). Larger responses are not cached |
--cacheHeaderName | Determines the name of the header added to the response given from the cache | A header name; the default is TRCACHE. By looking at this header the client understands that the response comes from the cache |
The Caching Rules
The rules determine which requests will be cached. Every rule is written with its own index and carries its own id.
| Field | Status | What it does | What is written after it |
|---|---|---|---|
--cacheRules.N.id | Required | Gives an id to the rule | The rule id; it must be unique within the profile. When a rule is added, this field has to be given |
--cacheRules.N.cond | Optional | Determines to which requests the rule will be applied | A condition expression; it is built from the lb condition records. If no condition is given, the rule matches every request |
--cacheRules.N.etag | Optional | Turns on the ETag header being added to the response; when the version has not changed, the client does not download the content again | true · false (default false) |
The Fields That Loosen the Matching Criterion
While the cache looks at whether a request is the same as a previously kept response, it takes the host header, the query string and the request and response headers into account by default. The fields below disable these criteria one by one: when they are turned on, different requests share the same response and the cache hit rate increases.
| Field | Default | What it does |
|---|---|---|
--ignoreHost | false | Ignores the Host header; the requests coming from different domain names share the same response |
--ignoreQuery | false | Ignores the query string; even if what comes after ? changes, the same response is given |
--ignoreRequestCheck | false | Ignores the request headers |
--ignoreResponseCheck | false | Ignores the response headers; the headers of the backend that prevent caching are not taken into account |
--allowCacheAllMethods | false | Ignores the HTTP method standards; the methods that are not normally cached are kept as well |
Loosening can return a wrong response
These fields narrow the distinguishing criterion of the cache. For example, when --ignoreQuery true is written, the same response is given to the ?id=1 and ?id=2 requests. They are turned on only in the places where the content really does not change.
Dynamic Caching
| Field | Status | What it does | What is written after it |
|---|---|---|---|
--dynamicCaching | Optional | Turns on the cache key being created from the request content | true · false (default false) |
--dynamicCachingKeys.N | Conditionally required | Determines the variables that make up the key | A smart variable; Tab lists the usable ones. When --dynamicCaching true is written at least one is needed; each is written with its own index and different from the others |
When dynamic caching is turned on, the responses are kept not as a single copy but separately according to the value of the selected variables. In this way the content that changes according to the user or to the request can be cached too.
Examples
Updating and Deleting
Things to Know
- A profile does not work on its own. The caching starts when the profile is bound to a vService with the
--cachefield. This field is found only in the vServices of the HTTP type. - The rule id is required. While a rule is being added,
--cacheRules.N.idhas to be given; the ids are unique within the profile. - The shortest duration is 10 seconds. A shorter value cannot be written in the
--timeoutfield; onlys,mandhare used as the unit. - The size limit is per response. The responses larger than the
--sizeMBvalue are not cached at all; the limit cannot exceed 2048 MB. - The name is unique. A second profile with the same name cannot be created.
