|
|
YOUR FEEDBACK
SOA World Conference
Virtualization Conference $200 Savings Expire May 16, 2008... – Register Today! Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON Application Server
Memory Caching in WAS
Caching can be implemented in portlets
By: Pooja Gupta; Sherman Lee
Aug. 17, 2005 01:00 PM
Digg This!
Page 1 of 2
next page »
Once upon a time if a development team wanted to implement memory caching, the developers had to code a Java Singleton class and maintain key value pairs using the Java API's hashtable in memory.
In this article I want to educate developers to use WAS's built-in caching mechanism. I'll also include a snippet of code and show you how easily it can be implemented in a portlets/Java program. WebSphere Application Server 5.x and above offer system defined APIs to implement Memory Cache/Command Cache. The cacheable commands are stored in the cache for reuse as and when pages are repeatedly requested. Each incoming request is cached as an object and is associated with an unique cache ID. These IDs can be generated based on the methods and fields (variables) defined in the command as input parameters. Command Caching can be implemented in portlets since portlets run on Portal Server, which in turn makes use of an instance of the WAS. The following sample program will show how to implement and integrate the command cache with portlets. This code was developed using Rational Application Developer (RAD). 1. First and foremost the jar files that come with the product should be included with the program in Listing 1 (else the code will not compile) (there are three of them and can be found in the following dir or WAS.):
3. Now create a regular servlet or a portlet that will run on WAS or WPS, respectively. (All the code in this case is in the same package, not mandatory to have all the code under same package) The following snippet of code (Listing 1) can be placed in Servlet or a Portlet (doGet or doView method accordingly) Listing 1
try 4. Now, we'll have to place the cachespec.xml with the servlet/portlet project. This xml file is placed in the web-inf folder. (This folder is created when we create a portlet project using the RAD.) Place the following entry in cachespec.xml (the cachespec.dtd can be found in the WAS Install dir\properties folder. (With this entry, we specified basis on which caching will happen within WAS)
<?xml version="1.0"?> (To get the XML allowed tag values, refer to the WAS infocenter.) After implementing this step the command cache is ready to use with the servlet/portlet. This sample code will cache the value of xmlResults on the basis of the fileName. If the fileName remains unchanged and chache is valid, the request will be addressed from the cache. Page 1 of 2 next page »
WEBSPHERE LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING WEBSPHERE NEWS
|
|||||||||||||||||||||||||||||||||||