Oracle9iAS Portal Developer Kit
How to Build a URL-Based Portlet that Uses Invalidation-Based Caching

PDK Release 2 (9.0.2 and later)


This article describes how to build a URL-based portlet that uses invalidation-based caching.

Invalidation caching is a very flexible caching mechanism that combines the best features of expiry and validation caching. Invalidation based caching is essentially expires based caching, with the added ability to "expire" or "invalidate" the contents of the cache at any time. Invalidation of cache content is usually triggered by some kind of "event" taking place.

For more information on invalidation-based caching and how it works, see the article, Setting up the Invalidation Caching Sample.

ASSUMPTIONS

  1. You have already gone over how to build a URL-based portlet by following the article, How to Build a URL-Based Portlet.
  2. You have enabled invalidation caching and defined a web cache invalidation port according to the article, Setting up the Invalidation Caching Sample.

CREATING AN XML PROVIDER DEFINITION

This section explains how to create an XML provider definition for your URL-based portlet provider.  You can configure your portlet to use invalidation-based caching in this XML file.

Using a text editor, create an XML file for your portlet provider. Use the useInvalidationCaching tag to configure the portlet to use invalidation-based caching. Use the pageExpires tag to indicate how many minutes the cache should be enabled for. You may use the sample xml file below (you must change the httpProxyHost and httpProxyPort values to point to your own proxy server and port). Please refer to the article Understanding provider.xml for URL-Based Portlets for an explanation of the required XML tags and their functions.

After you have created the file, save it somewhere on your file system and call it "provider.xml".

<?xml version="1.0" encoding="UTF-8"?>
<?providerDefinition version="3.1"?>
<provider class="oracle.portal.provider.v2.http.URLProviderDefinition">
<providerInstanceClass>oracle.portal.provider.v2.http.URLProviderInstance</providerInstanceClass>
<session>true</session> <proxyInfo class="oracle.portal.provider.v2.ProxyInformation">
<httpProxyHost>www-proxy.us.oracle.com</httpProxyHost>
<httpProxyPort>80</httpProxyPort>
</proxyInfo> <preferenceStore class="oracle.portal.provider.v2.preference.FilePreferenceStore">
<name>prefStore1</name>
<useHashing>true</useHashing>
</preferenceStore>
<portlet class="oracle.portal.provider.v2.http.URLPortletDefinition">
<id>1</id>
<name>InvalidationPortlet</name>
<title>Invalidation Portlet</title>
<description>Display Yahoo! as a portlet.</description>
<timeout>30</timeout>
<timeoutMessage>Yahoo! timed out</timeoutMessage>
<acceptContentType>text/html</acceptContentType> <showEdit>true</showEdit> <renderer class="oracle.portal.provider.v2.render.RenderManager"> <contentType>text/html</contentType> <autoRedirect>true</autoRedirect> <showPage class="oracle.portal.provider.v2.render.http.URLRenderer">
<contentType>text/html</contentType> <pageExpires>1</pageExpires>
<pageUrl>http://www.yahoo.com</pageUrl> <useInvalidationCaching>true</useInvalidationCaching>
<filter class="oracle.portal.provider.v2.render.HtmlFilter">
<headerTrimTag>&lt;body</headerTrimTag>
<footerTrimTag>/body></footerTrimTag>
</filter>
</showPage> <editPage class="oracle.portal.provider.v2.render.http.URLEditRenderer"/>
</renderer> <personalizationManager class="oracle.portal.provider.v2.personalize.PrefStorePersonalizationManager"> <dataClass>oracle.portal.provider.v2.URLPersonalizationObject</dataClass>
</personalizationManager>
</portlet>
</provider>

The above renderer will enable invalidation caching for one minute. Though there is no special way of detecting if it is cached or not, we can definitely see the difference in the page-loading time. The invalidation cache will remain active until

The first time a page request is made to the web provider via the cache, the response is cached. Subsequent requests for the portlet content will be fulfilled by returning content from Web Cache. When you change customization data an invalidation request is generated by the provider that removes the portlet from the cache. The next request for the portlet will be forwarded to the provider and the provider will generate a new portlet from the pageUrl.

Note: The pageExpires tag is also used for normal expiry based caching. These two forms of caching are mutually exclusive. Invalidation caching takes place in a Web Cache instance that is local to the web provider, pages stored using expiry based caching are cached in the middle tier of Oracle9iAS Portal.

DEPLOYING AND REGISTERING THE PORTLET

At this point, you are ready to deploy and register the portlet. The steps required to do this are the same steps as those described in the article, How to Build a URL-Based Portlet. Proceed by following all of the steps in that article. You should then be able to deploy and register your invalidation-based caching portlet in the exact same manner as the Google.com portlet described in the How to Build a URL-Based Portlet article.


Revision History: