
Command Cache
The dynamic cache service works by intercepting calls to cachable objects within the application server. Previously published articles (see Resources) show how to intercept a call to a servlet or portlet and cache the servlet output as an HTML fragment. WebSphere can also intercept a call to the execute() method of a command object and store the content of the object within the dynamic cache. Dynamic caching can also cache additional data types, such as Web services and patterns; those topics will be left for a later article.
As with servlet caching, command caching requires a unique cache ID as the key for storing and retrieving something from the cache. A key can be anything unique and based on methods and fields within your cachable object. For example, the key could be a unique user ID, a stock symbol or, in our case, a zip (postal) code.
The ability to cache command objects within WebSphere Application Server is configured using cachespec.xml. In earlier versions of WebSphere Application Server, configuration was performed using the servletcache.xml file. This file is still supported; however, cachespec.xml is the preferred and future approach. When you deploy the service, place the cachespec.xml in this directory:
The cachespec.xml (in the ZiptoLocService.jar in the download) is shown in Listing 1.
Listing 1. The cachespec.xml configuration file
|
The WebSphere
dynamic cache parses the XML file when the application is loaded within
the application server. The parameters used determine the names and
type of objects that are cached. There are many parameters and
configuration options available for the cachespec.xml file. (See the WebSphere Application Server Information Center in Resources.)
For example, you could have multiple occurrences of the
From:
http://www.ibm.com/developerworks/websphere/techjournal/0408_bernal/0408_bernal.html

