8.7 Portlet caching
Caching improves performance by reducing the load on the server. Caching is per user per portlet, a portlet cached for one user will not be used for another user. A JSR 168 portlet must use the portlet.xml to enable caching.
Example 8-19 Portlet caching in the portlet.xml
<portlet> ... <expiration-cache>600</expiration-cache> ... </portlet>
The expiration cache is defined in seconds. In the example above, the contents of the portlet should be cached for 10 minutes. A value of zero indicates that the portlet caching is disabled. A -1 value will cause the portlet cache to never expire. Any value above 0 will be interpreted as the number of seconds the content should be cached for.
If the expiration-cache is defined in the portlet.xml, the portlet may programmatically change the expiration time. The request property expiration-cache should be used to modify the caching values.
Example 8-20 Programmatically changing the expiration time-out value
RenderResponse.setProperty( PortletResponse.EXPIRATION_CACHE, (new Integer(600)).toString() );
While the portlet content is cached and the portlet is not a target of a request, the cached content will be used during the render phase. If there is a request for the portlet, the cached content will be disregarded and the render method of the portlet will be invoked.
ibm.com/redbooks