Expiry-based Caching Enhancing Portlet Performance with Caching

Enhancing Java Portlets 7-65

7.2.9.3 Adding Expiry-Based Caching

Expiry-based caching is one of the simplest caching schemes to implement, and can be activated declaratively in your XML provider definition. You can set an expiry time for the output of any ManagedRenderer you utilize by setting its pageExpires property to the number of minutes you want the output to be cached for. For example, suppose you want portlet output to be cached for one minute. To add expiry-based caching, perform the following steps:

1. After you have used the Portlet Wizard to build a portlet as described in

Section 6.5, Building Oracle PDK-Java Portlets with Oracle JDeveloper , edit the provider.xml file and set the pageExpires property tag of showPage to 1. This will set an expires entry of 1 minute for the portlet. By default the wizard generates a standard and compressed tag for showPage. You need to expand the tag to include a subtag of pageExpires: showPage class=oracle.portal.provider.v2.render.http.ResourceRenderer resourcePathhtdocsmycacheportletMyCachePortletShowPage.jsp resourcePath pageExpires1pageExpires showPage For more information on the syntax of provider.xml, refer to the provider Javadoc on OTN: http:www.oracle.comtechnologyproductsiasportalhtmljavadocx ml_tag_reference_v2.html 2. Test that the portlet is cached for 1 minute by adding some JSP code to your show page. You can simply add the current time to your JSP. page contentType=texthtml; charset=windows-1252 import=oracle.portal.provider.v2.render.PortletRenderRequest import=oracle.portal.provider.v2.http.HttpCommonConstants import=java.util.Date import=java.text.DateFormat PortletRenderRequest pReq = PortletRenderRequest request.getAttributeHttpCommonConstants.PORTLET_RENDER_REQUEST; DateFormat df = DateFormat.getDateTimeInstanceDateFormat.LONG, DateFormat.LONG,pReq.getLocale; String time = df.formatnew Date; PHello =pReq.getUser.getName .P PThis is the biEditib render modeP PThis information is correct as of =time.P When viewing the portlet, you see that the time including seconds is constant for 1 minute. After the time has expired, the portlet displays the most current time and a new cache is set.

7.2.9.4 Adding Invalidation Based Caching

When using Oracle Web Cache, requests for content are sent using HTTP and content is either returned from the cache or the HTTP request is forwarded to the originator of the content. When content is returned to Oracle Web Cache, it is added to the cache before being returned to the requestor. Cache content is invalidated by sending