AEM Dispatcher缓存哪些请求?

本文确定AEM Dispatcher未缓存的原因以及哪些HTTP请求/响应。

描述 description

环境

AEM Dispatcher 4.3.3

问题

本文档介绍了一些最重要的场景,这些场景会影响AEM Dispatcher模块缓存请求和响应的能力。 不包含所有缓存规则。

解决方法 resolution

HTTP请求和缓存规则

要使Dispatcher能够缓存HTTP请求,它必须遵循以下规则:

  1. URL是绝对路径(不适用于的。 具有文件扩展名,且URL中的文件名可用作文件系统中的文件。

    相关日志消息

    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
    

    示例

    table 0-row-2 1-row-2
    /content/test not cached
    /content/test.html cached
  2. 第一个文件扩展名后面没有斜杠。

    相关日志消息

    code language-none
    request URL has trailing slash
    

    示例

    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. 它使用HTTPGET或HEAD方法。

    相关日志消息

    code language-none
    request method is neither GET nor HEAD
    

    示例

    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. 在Dispatcher中定义的/CACHE => /RULES拒绝了请求。 任何场配置。

    相关日志消息

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

    示例

    a.未缓存

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

    b.缓存的

    code language-none
    Farm has /cache => /rules and a request is received for /content/test.html
    /cache
    {
      ...
      /rules
      {
        /0001 {
          type "allow"
          glob "*"
          }
      }
    }
    
  5. HTTP请求不包含授权标头,或者虽然包含该标头,但在场配置中将/ALLOWAUTHORIZED设置为1。

    相关日志消息

    code language-none
    request contains authorization
    

    示例

    a.未缓存

    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.缓存的

    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. HTTP请求在Cookie标头中包含登录令牌或授权Cookie,或者包含这些Cookie中的任意一个(或两者),并且在场配置中将/ALLOWAUTHORIZED设置为1。

    相关日志消息

    code language-none
    request contains authorization
    

    示例

    a.未缓存

    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.缓存的

    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. URL中存在QUERYSTRING参数,允许通过场的/IGNOREURLPARAMS配置忽略该参数。

    相关日志消息

    code language-none
    request contains a query string
    

    示例

    a.缓存

    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.未缓存

    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响应和缓存规则:

如果满足以下条件,则可以缓存从AEM返回的HTTP响应:

  1. Dispatcher能够发送和接收来自定义的“RENDERS”之一的“200 OK”响应。

    注意: 如果在/renders上未设置/timeout,或将它设置为0,那么它将永远等待与AEM实例的连接,即使该实例已关闭。

    相关日志消息

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

    示例

    table 0-row-2 1-row-2
    HTTP请求:

    200 OK
    cached
    HTTP请求:

    404页面未找到
    未缓存
  2. 响应中不存在以下任何响应标头:

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

    相关日志消息

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

    示例

    table 0-row-2 1-row-2 2-row-2 3-row-2
    HTTP响应:

    200 OK

    Dispatcher: no-cache
    未缓存
    HTTP响应:

    200 OK

    Cache-control: no-cache
    未缓存
    HTTP响应:

    200 OK

    Pragma: no-cache
    未缓存
    HTTP响应:

    200 OK
    cached
  3. Content-length值大于0字节。
    相关日志消息

    code language-none
    response content length is zero
    

    示例

    table 0-row-2 1-row-2
    HTTP响应:

    200 OK

    Content-Length: 0
    未缓存
    HTTP响应:

    200 OK

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