Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-25877

Cached asynchronous renderings using the request.parameters context entry are never reused when the request has parameters

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 10.10-rc-1
    • Rendering - Async
    • None
    • Unknown

    Description

      When an asynchronous rendering is cached and its context entries include request.parameters, the cached result is never reused as soon as the request has at least one parameter: the content is computed again on each view, even with exactly the same URL.

      Steps to reproduce

      1. Create a page with the following content:
        {{async cached="true" context="request.parameters"}}
        {{velocity}}$datetool.date{{/velocity}}
        {{/async}}
        
      2. View the page with a request parameter, e.g. ?foo=bar
      3. Reload the same URL

      EXPECTED RESULTS: the second view displays the cached result (same date as the first view).

      ACTUAL RESULTS: the content is computed again on each view (the date changes).

      Without any request parameter the cache works, since the map of parameters is empty.

      Cause

      DefaultAsyncRendererExecutor#getJobId builds the job id, which is also the key of the cached result, from String.valueOf() of each context entry value. The request.parameters entry is stored as a Map<String, String[]>, and the string representation of a String[] is based on its identity hash code (e.g. [Ljava.lang.String;@1b2c3d), which is different for each request. The same problem affects the request.cookies entry, stored as a Cookie[].

      Workaround

      Use the request.url context entry instead, which includes the query string and has a stable string representation. Note that the request restored for the asynchronous execution then has no parameters, so they have to be parsed from the URL.

      Environment

      Observed on XWiki 17.10.15 and 18.4.6 (Tomcat 10.1, MariaDB). The code involved has not changed since it was introduced in XWIKI-15640.

      Attachments

        Issue Links

          Activity

            People

              tmortagne Thomas Mortagne
              tmortagne Thomas Mortagne
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: