Product Documentation

Configuring Expressions for Caching Policies and Selectors

Oct 28, 2013

A request-time expression examines data in request-time transaction, and a response-time expression examines data in a response-time transaction. In a policy for caching, if an expression matches data in a request or response, the Citrix NetScaler appliance takes the action associated with the policy. In a selector, request-time expressions are used to find matching responses that are stored in a content group.

Before configuring policies and selectors for the integrated cache, you need to know, at minimum, the host names, paths, and IP addresses that appear in HTTP request and response URLs. And you probably need to know the format of entire HTTP requests and responses. Programs such as Live HTTP Headers (http://livehttpheaders.mozdev.org/) or HTTPFox (https://addons.mozilla.org/en-US/firefox/addon/6647) can help you investigate the structure of the HTTP data that your organization works with.

Following is an example of an HTTP GET request for a stock quote program:

 
GET /quote.dll?page=dynamic&mode=data&mode=stock&symbol=CTXS&page=multi&selected=CTXS&random=0.00792039478975548 HTTP/1.1 
Host: quotes.mystockquotes.com 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us,en;q=0.5 
Accept-Encoding: gzip,deflate,compress,pack200-gzip 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 300 
Connection: keep-alive 
Referer: http://quotes.mystockquotes.com/quote.dll?mode=stock&symbol=CTXS&page=multi&selected=CTXS 
Cookie: __qca=1210021679-72161677-10297606 

When configuring an expression, note the following limitations:

Table 1. Restrictions on Request-Time and Response-Time Expressions

Expression Type

Restrictions

Request

Do not configure request-time expressions in a policy with a CACHE or NOCACHE action. Use MAY_CACHE or MAY_NOCACHE instead.

Response

Configure response-time expressions in caching policies only.

  • Selectors can use only request-time expressions.
  • Do not configure response-time expressions in a policy with an INVAL action.

Do not configure response-time expressions in a policy with a CACHE action and a parameterized content group. Use the MAY_CACHE action.

Note: For a comprehensive discussion of advanced expressions, see "Policies and Expression."

Expression Syntax

Following are basic components of the syntax:

  • Separate keywords with periods (.), as follows:

    http.req.url

  • Enclose string values in parentheses and quotes, as follows:

    http.req.url.query.contains("this")

  • When configuring an expression from the command line, you must escape internal quote marks (the quotes that delimit values in the expression, as opposed to the quotes that delimit the expression). One method is to use a slash, as followings:

    \"abc\"

Selector expressions are evaluated in order of appearance, and multiple expressions in a selector definition are joined by a logical AND. Unlike selector expressions, you can specify Boolean operators and modify the precedence in an advanced expression for a policy rule.

Configuring an Expression in a Caching Policy or a Selector

Updated: 2014-08-04

Note that on the command line, the syntax for a policy expression is somewhat different from a selector expression. For a comprehensive discussion of advanced expressions, see "Policies and Expressions."

To configure a policy expression by using the command line interface

  1. Start the policy definition as described in "Globally Binding an Integrated Caching Policy."
  2. To configure the policy rule, delimit the entire rule in quotes, and delimit string values within the rule in escaped quotes.

     

    The following is an example:

    "http.req.url.contains(\"jpg\")"
    
  3. To add Boolean values, insert &&, ||, or ! operators.

     

    The following are examples:

    "http.req.url.contains(\"jpg\") || http.req.url.contains(\"jpeg\")"  
    "http.req.url.query.contains(\"IssuePage\")"  
    "http.req.header(\"Host\")contains(\"my.company.com\") && http.req.method.eq(\"GET\") && http.req.url.query.contains(\"v=7\")" 
    
  4. To configure an order of evaluation for the constituent parts of a compound

     

    "http.req.url.contains(\"jpg\") || (http.req.url.contains(\"jpeg\") && http.req.method.eq(\"GET\"))"
    

To configure a selector expression by using the command line interface

  1. Start the selector definition as described in "About Content Groups."
  2. To configure the selector expression, delimit the entire rule in quotes, and delimit string values within the rule in escaped quotes.

     

    The following is an example:

    "http.req.url.contains(\"jpg\")"
    
  3. You cannot add Boolean values, insert &&, ||, or ! operators. Enter each expression element delimited in quotes. Multiple expressions in the definition are treated as a compound expression joined by logical ANDs.

     

    The following are examples:

    "http.req.url.query.value(\"ProductId\")" "http.req.url.query.value(\"BatchNum\")" "http.req.url.query.value(\"depotLocation\")"
    

To configure a policy or selector expression by using the configuration utility

  1. Start the policy or selector definition as described in "To configure a policy for caching or invalidation by using the configuration utility" or "To configure a selector by using the configuration utility."
  2. In the Expression field, you can either manually type the default syntax by clicking Switch to Classic Syntax or create new expression using Expression Editor.
  3. To insert an operator between two parts of a compound expression, click the Operators button and select the operator type. The following is an example of a configured expression with a Boolean OR (signaled by double vertical bars, ||):
  4. Click Frequently Used Expressions drop-down to insert the commonly used expressions.
  5. To test the expression, click the Evaluate. In the Expression Evaluator dialog box, select the Flow Type that matches the expression. In the data field, paste the HTTP request or response that you hope to parse using the expression, and click Evaluate.