Invalidation-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 7-66 Oracle Fusion Middleware Developers Guide for Oracle Portal invalidation requests directly to Oracle Web Cache. PDK-Java uses the Java API for Web Cache JAWC to generate invalidation requests. This section describes how to configure Oracle Web Cache and use the invalidation-based caching sample that comes with PDK-Java. Not all requests sent to Oracle Web Cache are cached. In order for the content to be cached, the content must include directives that tell Oracle Web Cache to cache the content. Usually Oracle Web Cache uses the URL associated with the request as the cache key, but you can specify additional keys by setting special HTTP headers, known as surrogate control headers, on the response. To configure a Java portlet to use invalidation-based caching, you do the following: ■ Configuring Oracle Web Cache. Refer to Oracle Fusion Middleware Administrators Guide for Oracle Web Cache for more information. ■ Section 7.2.9.4.1, Configuring the Provider Servlet ■ Section 7.2.9.4.2, Defining the Oracle Web Cache Invalidation Port ■ Section 7.2.9.4.3, Configuring the XML Provider Definition ■ Section 7.2.9.4.4, Manually Invalidating the Cache

7.2.9.4.1 Configuring the Provider Servlet To enable invalidation-based caching, you must

switch it on at the provider servlet level. The flag is set in an initialization parameter inside the PDK-Java Web application deployment descriptor, web.xml. For example: servlet ... servlet-classoracle.webdb.provider.v2.adapter.SOAPServletservlet-class init-param param-nameinvalidation_cachingparam-name param-valuetrueparam-value init-param servlet If the flag is not defined here, then invalidation-based caching is switched off. The status of this flag can be checked by displaying the providers test page. If the testPageURI property is not set in the sample.properties file, then the provider code displays the test page in the old default style. The old style test page correctly picks up the invalidation caching flag from the web.xml file. The format of the test page URL is as follows: http:provider_hostname:portjpdkproviderssample

7.2.9.4.2 Defining the Oracle Web Cache Invalidation Port If you are using an Oracle

Application Server installation type where PDK-Java was automatically pre-installed for example, an Oracle Portal and Wireless type installation, you should find that Oracle Web Cache invalidation settings have already been preconfigured in MID_ TIER_ORACLE_HOMEportalconfcache.xml. In this case, you can safely ignore the instructions in this section and proceed to Section 7.2.9.4.3, Configuring the XML Provider Definition . Otherwise, you will need to configure the invalidation portlet for Oracle Web Cache. First, you need the user name and password for the invalidation ports of the Oracle Web Cache instances associated with your application server. After you obtain those, use the provided oracle.webdb.provider.v2.cache.Obfuscate Java utility to convert the user name and password into an obfuscated string of the format required by the JAWC API. In a default Oracle Application Server installation, the user name for the invalidation port is usually invalidator and the password is usually the