Portlet Caching

When you have more than one portlets on a page and you perform action on one portlet, this results into invocation of processAction of one portlet and redering of rest all portlets.

To stop rendering n-1 portlets, JSR 168 spec defines a caching method called expiration based caching mechanism and this caching mechanism is per portlet.

This caching basically stops executing render methods of n-1 portlets and this definitely improves performance of overall page rendering.

How to achieve this type of caching.

define <expiration-cache> entry in the portlet.xml for the portlet you want to cache. This entry takes time in seconds.

example:-
define following entry in portlet.xml after <portlet-class> tag

<portlet>
......
......
<expiration-cache>300</expiration-cache>
....
.....
<portlet>

here 300 is time value in seconds.

This entry tells to container that, cache the data of this portlet for 300 seconds unless any action is performed on this portlet.

Meaning, if you have 300 seconds (5 minutes) set for a portlet A and you are performing some actions on portlet B on the same page, then processAction of portlet B will be called and portlet A data will be shown from cache.
In between, if you perform any action on portlet A, then cached data will be discarded and corresponding request handling methods of the portlet like processAction or processEvent will be invoked.

Also, If you set expiration property in portlet.xml to 0, the returned markup fragment should be treated as always expired and if the expiration cache property is set to –1, the cache does not expire.

Also have a look at Configuring Portlet Caching on Server

Portlet's cache can also be altered programmatically by following piece of code

renderResponse.setProperty(RenderResponse.EXPIRATION_CACHE, "400");

2 comments:

Naga Dakshina Murthy Nookala said...

Include the steps required to be done on the portal server container also to make it complete
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/tdyn_portletcaching.html

Neeraj Sidhaye said...

thanks for the information Naga.
I have updated the post.