Enabling the portlet URL JSP Cache using the GET method

Out of the two GET and POST methods, portlet URL caching using the GET method is simpler and can almost mimic the <portlet:actionURL> and <portlet:renderURL> tags. The enablement should be performed in the original portlet JSP file.

Procedure

  1. At the top of the portlet JSP file, declare the new cache tag library using cache as the prefix.
  2. For all portlet action URLs that use the GET method, substitute all occurrences of <portlet:actionURL> with <cache:actionURL>.
  3. For all portlet render URLs, substitute all occurrences of <portlet:renderURL> with <cache:renderURL>.

Results

When WebSphere Portal renders this portlet JSP file for the first time upon a cache miss, the following sequence of events occurs:

  1. The portlet JSP file is compiled into byte code.
  2. If the cache tag detects no DCP object associated with the current page context, a new DCP is created and initialized. Each cache tag is responsible to register all its associated properties, such as parameters and the name of the variable to store the portlet URL, to the DCP for the callback handler to know how to regenerate the given portlet URL upon a cache hit.
  3. The cache tag needs to return a text string back to the JSP file, where it can be associated with other HTML tags, similar to the existing portlet URL tag. This text string is generated such that the initial portlet URL can be overwritten by another JavaScript variable at a later time, if it exists.
    This text string is a generated JavaScript string in the following format:
    
    if (typeof(variableName) == 'undefined') {
        location.href = "/wps/portal/…";
    } else {
        location.href = variableName;
    }
    
    Where variableName is another JavaScript variable that is generated by the DCP upon the next cache hit. As DCP is not called on a cache miss, this JavaScript variableName is not yet defined and therefore the original portlet URL is instead used.

Upon a cache hit the next time the same request is detected, the following sequence of events occurs:

  1. The provideDynamicContent() callback method in the DCP object is invoked and generates the following JavaScript code to the beginning of the cached content fragment:
    
    <script language="javascript">
        var variableName = '/wps/portal/…';
    </script>
    
  2. When this code snippet is loaded into the user's Web browser with the cached fragment, it triggers the previously generated JavaScript to use the portlet URL declared in this new JavaScript variable variableName, instead of the one that has been cached.