Configure policies for caching and invalidation
-
Caching actions. Policies that you associate with the CACHE action store responses in the cache and serve them from the cache.
-
Invalidation actions. Policies that you associate with the INVAL action immediately expire cached responses and refresh them from the origin server. For Web-based applications, invalidation policies often evaluate POST requests.
-
“Do not cache” actions. Policies that you associate with a NOCACHE action never store objects in the cache.
-
Provisionally cache actions. Policies that you associate with a MAYCACHE or MAYNOCACHE action depend on the outcome of more policy evaluations.
LOCK request. For invalidation policies only, you can specify LOCK as a method by using the expression http.req.method.eq(“lock”). Unlike policies for GET and POST requests, you must enclose the LOCK method in quotes because the NetScaler appliance recognizes this method name as a string only.
Actions to associate with integrated caching policies
| Action | Specification |
|---|---|
| CACHE | Serves a response from the cache if the response has not expired. If the response must be fetched from the origin server, the NetScaler appliance caches the response before serving it. Even data that is updated and accessed frequently can be cached. For example, stock quotes are updated frequently, but they can be cached so that they can be served quickly to multiple users. If necessary, cached data can be refreshed immediately after it is downloaded. A CACHE action can be overridden by built-in policies. |
| NOCACHE | Always fetches the response from the origin server and marks the response as non-storable. You typically configure NOCACHE policies for data that is sensitive or personalized. |
| MAY_CACHE | Used in a request-time policy, this setting provisionally enables a response to be stored in a content group, pending evaluation of response-time policies. The following are possible: 1. If a matching response-time policy has a CACHE action but does not specify a content group, the response is stored in the Default group unless built-in policies override this policy. 2. If a matching response-time policy has a CACHE action and specifies the same content group as the one in the request-time policy, the response is stored in the named content group unless built-in policies override this policy. 3. If a matching response-time policy has a CACHE action but specifies a different content group from the one in the request-time policy, a NOCACHE action is applied. 4. If a matching response-time policy has a NOCACHE action, perform a NOCACHE action. 5. If there is no matching response-time policy, a CACHE action is applied, unless a built-in policy overrides this policy. |
| MAY_NOCACHE | For a request-time policy, this setting provisionally prevents caching the response. At response time, one of the following actions is taken: - If no response-time policy matches the request, the final action is NOCACHE. - If a matching response-time policy contains a CACHE action, the final action is CACHE, unless built-in policies override this policy. - If a matching response-time policy contains a NOCACHE action, the final action is NOCACHE. -If a matching response-time policy has a CACHE action but does not specify a content group, the final action is to CACHE the response in the Default content group, unless built-in policies override this policy. |
| INVAL | Expires cached responses. Depending on how the policy and the content group are configured, all responses in one or more content groups are expired, or selected objects in the content group are expired. Note: You can specify INVAL actions in request-time policies only. |
Bind points for a policy
-
A global policy bank. These are the request-time default, request-time override, response-time default, and response-time override policy banks, as described in "Order of Policy Evaluation."
-
A virtual server. Policies that you bind to a virtual server are processed after the global override policies and before the global default policies, as described in "Order of Policy Evaluation." When binding a policy to a virtual server, you bind it to either request-time or response-time processing.
-
An ad-hoc policy label. A policy label is a name assigned to a policy bank. In addition to the global labels, the integrated cache has two built-in custom policy labels:
-
_reqBuiltinDefaults. This policy label, by default, is invoked from the request-time default policy bank.
-
_resBuiltinDefaults. This policy label, by default, is invoked from the response-time default policy bank.
-
Order of policy evaluation
-
Request-time override. If a request matches a request-time override policy, by default the request-time policy evaluation ends and the NetScaler appliance stores the action that is associated with the matching policy.
-
Request-time load balancing virtual server. If policy evaluation cannot be completed after all the request-time override policies are evaluated, the NetScaler appliance processes request-time policies that are bound to load balancing virtual servers. If the request matches one of these policies, evaluation ends and the NetScaler appliance store the action that is associated with the matching policy.
-
Request-time content switching virtual server. Policies that are bound to this bind point are evaluated after the request-time policies that are bound to load balancing virtual servers.
-
Request-time default. If policy evaluation cannot be completed after all the request-time, virtual server-specific policies are evaluated, the NetScaler appliance processes the request-time default policies. If the request matches a request-time default policy, by default the request-time policy evaluation ends and the NetScaler appliance stores the action that is associated with the matching policy.
-
Response-time override. Similar to request-time override policy evaluation.
-
Response-time load balancing virtual server. Similar to request-time virtual server policy evaluation.
-
Response-time content switching virtual server. Similar to request-time virtual server policy evaluation.
-
Response-time default. Similar to request-time default policy evaluation.
NOCACHE action for POST requests and a MAY_NOCACHE action for requests with cookies. You would associate MAY_CACHE or MAY_NOCACHE actions with a request-time policy that points to a parameterized content group. The response time policy determines whether the transaction is stored in the cache.
Configure a policy for integrated caching
-
Rule: A logical expression that evaluates an HTTP request or response.
-
Action: You associate a policy with an action to determine what to do with a request or response that matches the policy rule.
add cache policy <policyName> -rule <expression> -actionCACHE|MAY_CACHE|NOCACHE|MAY_NOCACHE [-storeInGroup <contentGroupName>] [-undefAction NOCACHE|RESET] > add cache policy image_cache -rule "http.req.url.contains(\"jpg\") || http.req.url.contains(\"jpeg\")" -action CACHE -storeingroup myImages_group -undefaction NOCACHE
> add cache policy bugReportPolicy -rule "http.req.url.query.contains(\"IssuePage\")" -action CACHE -storeInGroup bugReportGroup
> add cache policy my_form_policy -rule "http.req.header(\"Host\")contains(\"my.company.com\") && http.req.method.eq(\"GET\") && http.req.url.query.contains(\"v=7\")" -action CACHE -storeInGroup my_form_event
> add cache policy viewproducts_policy –rule "http.req.url.contains(\"viewproducts.aspx\")" –action CACHE -storeInGroup Product_Details
add cache policy <policyName> -rule <expression> -action INVAL [-invalObjects "\<contentGroupName1>[,<selectorName1>"]. . .]] | [-invalGroup \<contentGroupName1>[, <contentGroupName2>. . .]] [-undefAction NOCACHE|RESET]> add cache policy invalidation_events_policy -rule "http.req.header("Host")contains("my.company.com") && http.req.method.eq("GET") && http.req.url.query.contains("v=8") -action INVAL -invalObjects my_form_event -undefaction NOCACHE> add cache policy inval_all -rule "http.req.method.eq("POST") && http.req.url.contains("jpeg")" -action INVAL -invalGroups myImages_group myApps_group PDF_group> add cache policy bugReportInvalidationPolicy -rule "http.req.url.query.contains(\"TransitionForm\")" -action INVAL -invalObjects bugReport`
`> add cache policy editproducts_policy –rule "http.req.url.contains(\"editproducts.aspx\")" –action INVAL -invalObjects "Product_Details,batchnum_sel" "Products_In_Depots,batchid_sel"
Globally binding an integrated caching policy
bind cache global <policy> -priority <positiveInteger> [-typeREQ_OVERRIDE|REQ_DEFAULT|RES_OVERRIDE|RES_DEFAULT] [-gotoPriorityExpression <expression>] [-invoke <labelType> <labelName>]> bind cache global myCachePolicy -priority 100 -type req_default
> bind cache global myCache Policy 200
Bind an integrated caching policy to a virtual server
bind lb vserver <name>@ -policyName <policyName> -priority <positiveInteger> -type(REQUEST|RESPONSE)bind cs vserver <name>@ -policyName <policyName> -priority <positiveInteger> -type(REQUEST|RESPONSE)
-
CS Virtual Server - Navigate toTraffic Management > Content Switching > Virtual Servers, select the virtual server, and bind relevant cache policies.
-
LB Virtual Server - Navigate toTraffic Management > Load Balancing > Virtual Servers, select the virtual server, and bind relevant cache policies.
How to cache compressed and uncompressed versions of a file
Accept-Encoding:compression format header is sent in the request. The compression type accepted by the client must match the compression type of the cached object. For example, a cached.gzip file cannot be served in response to a request with an Accept-Encoding:deflate header.
add cache selector uncompressed_response_selector http.req.url "http.req.header(\"Host\")"
add cache contentGroup uncompressed_group -hitSelector uncompressed_responst_selector -invalSelector uncomp_resp_sel
add cache policy cache_uncompressed -rule "HTTP.REQ.URL.CONTAINS(\"xyz\") && !HTTP.REQ.HEADER(\"Accept-Encoding\").EXISTS" -action CACHE -storeInGroup uncompressed_group
bind cache global cache_uncompressed -priority 100 -gotoPriorityExpression END -type REQ_OVERRIDE
add cache selector compressed_response_selector HTTP.REQ.URL "HTTP.REQ.HEADER(\"Host\")" "HTTP.REQ.HEADER(\"Accept-Encoding\")"
add cache contentGroup compressed_group -hitSelector compressed_response_selector
add cache policy cache_compressed -rule "HTTP.REQ.URL.CONTAINS(\"xyz\") && HTTP.REQ.HEADER(\"Accept-Encoding\").EXISTS" -action CACHE -storeInGroup compressed_group
bind cache global cache_compressed -priority 200 -gotoPriorityExpression END -type REQ_OVERRIDE
Configure a policy bank for caching
| Attribute | Specifies |
|---|---|
| Name | The name of a policy, or, to invoke another policy bank without evaluating the policy, the keyword NOPOLICY. You can specify NOPOLICY more than once in a policy bank, but you can specify a named policy only once. |
| Priority | An integer. The lower the integer, the higher the priority. |
| Goto Expression | Determines the next policy or policy bank to evaluate. You can provide one of the following values: 1. NEXT: Go to the policy with the next higher priority. 2. END: Stop evaluation. 3. USE_INVOCATION_RESULT: Applicable if this entry invokes another policy bank. If the final Goto in the invoked bank has a value of END, evaluation stops. If the final Goto is anything other than END, the current policy bank performs a NEXT. 4. Positive number: Priority number of the next policy to be evaluated. 5. Numeric expression: Expression that produces the priority number of the next policy to be evaluated. The Goto can only proceed forward in a policy bank. Omitting the Goto expression is the same as specifying END. |
| Invocation Type | Designates a policy bank type. The value can be one of the following - 1. Request virtual server: Invokes request-time policies that are associated with a virtual server. 2. Response virtual server: Invokes response-time policies that are associated with a virtual server. 3. Policy label: Invokes another policy bank, as identified by the policy label for the bank. |
| Invocation Name | Name of a virtual server or a policy label, depending on the value that you specified for the Invocation Type. |
_reqBuiltInDefaults: This policy label is invoked from the request-time default bind point. _resBuiltInDefaults: This policy label is invoked from the response-time default bind point.
bind cache policylabel <labelName> -policname<policyName> -priority<priority> [-gotoPriorityExpression <gotopriorityExpression>] [-invoke <labelType> <labelName>]
-
Navigate to Optimization > Integrated Caching, click Cache policy manager, and specify the relevant bind point (Override Global or Default Global) and connection type to view the list of policies bound to this bind point.
-
If you want to invoke a policy label without evaluating a policy, click NOPOLICY.
bind lb vserver <name>@ -policyName <policyName>|<NOPOLICY-CACHE> -priority<positiveInteger> -gotoPriorityExpression <expression> -type REQUEST|RESPONSE -invoke<labelType> <labelName>bind cs vserver <name> -policyName <policyName>|<NOPOLICY-CACHE> -priority<positiveInteger> -gotoPriorityExpression <expression> -type REQUEST|RESPONSE -invoke<labelType> <labelName>
-
Navigate to Traffic Management > Load Balancing/Content Switching > Virtual Servers, select the virtual server, and click Policies.
-
If you are configuring an existing entry in this bank, skip this step. If you are adding a new policy to this policy bank, or you want to use the “dummy” NOPOLICY entry, click Add and do one of the following:
-
To configure a new policy, click Cache and configure the new policy as described in Configuring a Policy in the Integrated Cache.
-
To invoke a policy bank without processing a policy a rule, select the
NOPOLICY-CACHEoption.
-
Configure a policy label in an integrated cache
\_reqBuiltinDefaults and \_resBuiltinDefaults. You can invoke a policy label any number of times unlike a policy, which can only be invoked once.
NOPOLICY “dummy” policy to invoke any policy label from another policy bank. The NOPOLICY entry is a placeholder that does not process a rule.
-
add cache policylabel <labelName> -evaluates (REQ|RES) -
show cache policylabel <labelName>
Unbind and delete an integrated caching policy and policy label
unbind cache global <policy>
(unbind lb vserver|unbind cs vserver) <vserverName> -policyName <policyName> -type(REQUEST|RESPONSE)
rm cache policy <policyName>
-
Navigate to Optimization > Integrated Caching, click Cache policy manager, and specify the relevant binding point (load balancing virtual server or content switching virtual server) and connection type to view the list of cache policies bound to this virtual server.
-
In the policy Invoke column, clear the entry.