Which requests does AEM Dispatcher cache?

This article determines why and which HTTP requests/responses are not being cached by the AEM Dispatcher.

Description description

Environment

AEM Dispatcher 4.3.3

Issue

The documentation covers the most important scenarios that affect the cache-ability of requests and responses which go through the AEM Dispatcher module. All cache rules are not covered.

Resolution resolution

HTTP Request & Caching Rules

For an HTTP request to be cacheable by the dispatcher, it must adhere to the following rules:

  1. URL is absolute (not working with . or …), has a file extension, and the filename in the URL works as a file on the file system.

    Related log messages:

    code language-none
    URI not canonical: %s.
    
    Unable to map URI to file: %s.
    
    cache file path too long
    
    temporary file path too long
    
    request URL has no extension
    

    Examples:

    table 0-row-2 1-row-2
    /content/test not cached
    /content/test.html cached
  2. It has no slashes after the first file extension.

    Related log messages:

    code language-none
    request URL has trailing slash
    

    Examples:

    table 0-row-2 1-row-2 2-row-2
    /content/test.html/ not cached
    /content/test.html/foo.jpg not cached
    /content/test.html cached
  3. It uses HTTP GET or HEAD method.

    Related log messages:

    code language-none
    request method is neither GET nor HEAD
    

    Examples:

    table 0-row-2 1-row-2 2-row-2
    HEAD /content/test.html HTTP/1.1 cached
    GET /content/dam/test.jpg HTTP/1.1 not cached
    POST /content/test.html HTTP/1.1 not cached
  4. The request is denied by /CACHE => /RULES defined in the dispatcher. ANY FARM CONFIGURATION.

    Related log messages:

    code language-none
    URI not  in cache rules: %s request URL not in cache rules
    

    Examples:

    a. Not cached

    code language-none
    Farm has /cache => /rules and a request is received for /content/test.html
    /cache
    {
      ...
      /rules
      {
        /0001 {
          type "deny"
          glob "*"
          }
      }
    }
    

    b. Cached

    code language-none
    Farm has /cache => /rules and a request is received for /content/test.html
    /cache
    {
      ...
      /rules
      {
        /0001 {
          type "allow"
          glob "*"
          }
      }
    }
    
  5. The HTTP request does not contain an authorization header or it contains the header but /ALLOWAUTHORIZED is set to 1 in the FARM CONFIGURATION.

    Related log messages:

    code language-none
    request contains authorization
    

    Examples:

    a. Not cached

    code language-none
    HTTP Request:
    
    GET /content/test.html HTTP/1.1
    Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
    dispatcher.any farm /cache => /allowAuthorized configuration:
    /cache {
     /allowAuthorized “0”
    }
    

    b. Cached

    code language-none
    HTTP Request:
    
    GET /content/test.html HTTP/1.1
    Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
    dispatcher.any farm /cache => /allowAuthorized configuration:
    /cache {
     /allowAuthorized “1”
    }
    
  6. The HTTP request contains login-token or authorization cookie in the cookie header, or it contains either (or both) of those cookies and /ALLOWAUTHORIZED is set to 1 in the FARM CONFIGURATION.

    Related log messages:

    code language-none
    request contains authorization
    

    Examples:

    a. Not cached

    code language-none
    HTTP Request:
    
    GET /content/test.html HTTP/1.1
    Cookie: login-token=...
    dispatcher.any farm /cache = /allowAuthorized configuration:
    /cache {
     /allowAuthorized “0”
    }
    
    code language-none
    HTTP Request:
    
    GET /content/test.html HTTP/1.1
    Cookie: authorization= YWxhZGRpbjpvcGVuc2VzYW1l
    dispatcher.any farm /cache = /allowAuthorized configuration:
    /cache {
     /allowAuthorized “0”
    }
    

    b. Cached

    code language-none
    HTTP Request:
    
    GET /content/test.html HTTP/1.1
    Cookie: login-token=...
    dispatcher.any farm /cache => /allowAuthorized configuration:
    /cache {
     /allowAuthorized “1”
    }
    
  7. There’s a QUERYSTRING parameter in the URL and the parameter is allowed to be ignored via the FARM’S /IGNOREURLPARAMS CONFIGURATION.

    Related log messages:

    code language-none
    request contains a query string
    

    Examples:

    a. Cached

    code language-none
    HTTP Request:
    
    GET /content/test.html?test=1 HTTP/1.1
    Farm /cache configuration:
    
    /ignoreUrlParams {
        /0001 { /type “allow” /glob “*” }
    }
    
    code language-none
    HTTP Request:
    
    GET /content/test.html?test=1 HTTP/1.1
    Farm /cache configuration:
    /ignoreUrlParams {
        /0001 { /type “deny” /glob “*” }
        /0001 { /type “allow” /glob “test” }
    }
    

    b. Not cached

    code language-none
    HTTP Request:
    
    GET /content/test.html?test=1 HTTP/1.1
    dispatcher.any farm /cache = /allowAuthorized configuration:
    /ignoreUrlParams {
        /0001 { /type “deny” /glob “*” }
        /0001 { /type “allow” /glob “q” }
    }
    

HTTP Response & Caching Rules:

The HTTP response returned from AEM is cacheable if the following criteria are met:

  1. The dispatcher is able to send and receive a 200 OK response from one of the defined “RENDERS”.

    Note: If no /timeout is set on the /renders or it is set to 0 then it would wait forever for a connection to the AEM instance even if the instance is down.

    Related log messages:

    code language-none
    Unable to send request to remote server. Unable to receive response from remote server. Remote server returned: %s No backend available.
    

    Examples:

    table 0-row-2 1-row-2
    HTTP Request:

    200 OK
    cached
    HTTP Request:

    404 Page Not Found
    not cached
  2. None of these response headers are present in the response:

    • Dispatcher: no-cache
    • Cache-control: no-cache
    • Pragma: no-cache

    Related log messages:

    code language-none
    Backend forbids caching: %s, sent: %s" response contains no_cache
    

    Examples:

    table 0-row-2 1-row-2 2-row-2 3-row-2
    HTTP Response:

    200 OK

    Dispatcher: no-cache
    not cached
    HTTP Response:

    200 OK

    Cache-control: no-cache
    not cached
    HTTP Response:

    200 OK

    Pragma: no-cache
    not cached
    HTTP Response:

    200 OK
    cached
  3. Content-length value is greater than ZERO BYTES.
    Related log messages:

    code language-none
    response content length is zero
    

    Examples:

    table 0-row-2 1-row-2
    HTTP Response:

    200 OK

    Content-Length: 0
    not cached
    HTTP Response:

    200 OK

    Content-Length: 3120
    cached
recommendation-more-help
3d58f420-19b5-47a0-a122-5c9dab55ec7f