YOUR FEEDBACK
JavaOne 2008: Chris Keene's Prescription for Curing the Java Flu
Rob wrote: I have to agree with Chris - I have been a developer and Java a...
SOA World Conference
Virtualization Conference
$200 Savings Expire May 16, 2008... – Register Today!

SYS-CON.TV
TOP THREE LINKS YOU MUST CLICK ON


Memory Caching in WAS
Caching can be implemented in portlets

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.

The IT industry has evolved and so has the caching mechanism. WebSphere Application Server (WAS) 5.x now comes with build-in, easy-to-use caching APIs. By implementing WAS's built-in caching feature, developers can configure caching for their application in a couple of hours. The WAS caching feature is quite sleek since it comes with cache monitor (which needs to be installed, but it's a very easy installation). This cache monitor helps developers view the cache contents, clear the cache, and so on.

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.):

  • Installdir WAS/lib/commands.jar
  • Installdir WAS/lib/ distexcep,jar
  • Installdir WAS/lib/ dynacache.jar
2.  Implement a cache command interface as shown in Listing 2

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
{
//Reading a xml file
SampleCacheCommnad scc=new
SampleCacheCommnad("c:/websphere/portalserver/shared/app/sample.xml");
scc.execute();
String XMLDoc=scc.getXmlresult();
System.out.println("Command Cache working... ");
}
  catch(Exception e)
{
  System.out.println("The command cache exception"+e);
}

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"?>
<!DOCTYPE cache SYSTEM "cachespec.dtd">
<cache>
<cache-entry>
  <class>command</class>
  <sharing-policy>not-shared</sharing-policy>
  <name>com.ibm.websphere.sample.SampleCacheCommand</name>
  <cache-id>
   <component type="method" id="getFilename">
   <required>true</required>
   </component>
   <priority>2</priority>
   <timeout>3600</timeout>
    </cache-id>
   </cache-entry>
</cache>

(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 »

About Pooja Gupta
Pooja Gupta is staff software engineer with IBM Software Group. She has seven years of experience in the IT field. She holds a Bachelor degree in Computer Science and is an IBM Certified WebSphere Portal 5.0 Solution Developer. Her areas of expertise include working on WebSphere products and end-to-end development of J2EE architecture?based Web applications. She is a technical writer in internal IBM Redbook.

About Sherman Lee
Sherman Lee is a Consulting I/T Specialist with the IBM Software Group. Since joining the IBM Software Group from IBM Global Services where he previously served as an infrastructure architect, Sherman has been a technical leader in the Upstate NY/New England area covering WebSphere technologies and more recently specializing within the Portal and IBM Workplace products. Sherman holds a Bachelor degree in Computer Engineering and is also an IBM Certified professional with over 10 years experience.

was5118 wrote: Authors do not mention the SampleCacheCommand class must implement com.ibm.we bsphere.command.Cacheable Command or extend com.ibm .websphere.command.Cachea bleCommandImpl, also source code is not provided for download. I would encourage readers to visit IBM Tech Journal for a helpful caching example: http://www.ibm.c om/developerworks/websphe re/techjournal/0408_berna l/0408_bernal.html
read & respond »
WEBSPHERE LATEST STORIES . . .
ParAccel Announces OEM Relationship with IBM
ParAccel announced it has entered into an original equipment manufacturer (OEM) agreement with IBM. Under the terms of the agreement, ParAccel will embed IBM InfoSphere Change Data Capture within the ParAccel Analytic Database, providing ParAccel customers with seamless and real-time u
Microsoft To Keynote 4th International Virtualization Conference & Expo
Mike Neil is general manager for virtualization strategy in the Windows Server Division at Microsoft. Mike is focused on the delivery of the Windows virtualization technology, including Windows Server 2008 Hyper-V, Microsoft Hyper-V Server and Virtual PC 2007. Mike also directs the tec
Micro Focus Upgrades SOA Express for IBM CICS
Micro Focus announced the availability of SOA Express 8.0. The new version adds support for direct deployment into IBM's Customer Information Control System (CICS), enabling users to accelerate the deployment of Web services by reusing their existing CICS TS mainframe infrastructure in
3rd International Virtualization Conference & Expo: Themes & Topics
From Application Virtualization to Xen, a round-up of the virtualization themes & topics being discussed in NYC June 23-24, 2008 by the world-class speaker faculty at the 3rd International Virtualization Conference & Expo being held by SYS-CON Events in The Roosevelt Hotel, in midtown
Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
Red Hat is a trusted open source provider. Red Hat offers enterprise customers a long-term plan for building infrastructures on the quality and innovation of open source. Combining open source operating system platform, Red Hat Enterprise Linux, together with applications, management
Migration from IBM Rational Application Developer to MyEclipse 6.5 Blue Edition
Genuitec announced the availability of the milestone release of MyEclipse 6.5 Blue Edition, a tailored, customizable tool suite for WebSphere developers. Notably, this initial release of MyEclipse 6.5 Blue Edition offers project migration support. Developers currently working with IBM
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING WEBSPHERE NEWS
Thunderhead and IBM Leverage ACORD Standards to Improve Agent and Customer Communications for Insurance Carriers
Thunderhead, a provider of enterprise communications solutions, today announced a new