Configuration steps

1. Enabling servlet and JSP result caching.

To enable servlet caching, enable the dynamic cache service for the Web container by performing these steps: a. Open the Administrative Console. b. Click Servers - > Application Servers in the console navigation tree. c. Select your appserver. d. Click Web Container. e. Select the Enable servlet caching check box under the Configuration tab. f. Click Apply or OK.

2. Configure cachespec.xml.

In the runtime environment, the cache parses the cachespec.xml file on startup, and extracts from each <cache-entry> element a set of configuration parameters. Every time a new servlet or other cacheable object initializes, the cache attempts to match each of the different <cache-entry> elements, to find the configuration information for that object. Different cacheable objects have different <class> elements. You can define the specific object a cache policy refers to using the <name> element.

As mentioned before, we are using Trade3 for this scenario. The cachespec.xml file for Trade3 can be found inside the WEB-INF directory of the Web module found in

<install_root>\installedApps\dmNetwork\Trade3.ear\trade3Web.war\WEB-INF

Refer to the WebSphere InfoCenter for a detailed description of cachespec.xml file elements. The InfoCenter can be found at

http://www.ibm.com/software/webservers/appserv/infocenter.html

 

Editing Trade3 cachespec.xml file

This section explains the cache entries for the Trade3 home servlet (see Figure 14-3). This page contains the following cacheable fragments (formatted or non-formatted):
Home servlet - Uses tradehome.jsp to format an output
marketSummary.jsp - tradehome.jsp includes marketSummary.jsp
Market summary command
Account command
Closed order command
Holdings command

For the purpose of demonstrating servlet and JSP result caching we use the cachespec.xml file only with home servlet and market summary JSP cache entries.

1. First, the cache-entry element for the home servlet needs to be specified. In this case, the servlet's URI is "/app" so this will be our cache-entry's name element. Also, since this cache-entry is a servlet, the cache-entry class is "servlet". See Example 14-1:

Example 14-1 Cache entry for home servlet

<cache>
	<cache-entry>
      	<class>servlet</class>
      	<name>/app</name>
	</cache-entry>
</cache>

2. Example 14-2 shows a definition of cache ID generation rules. The home servlet can be cached only when "action=home" and the servlet engine can retrieve the "JSESSIONID" cookie value (a user needs to be logged in). Therefore one component of the cache ID will be the parameter "action" when the value equals "home". The second parameter will be JSESSIONID which equals to the valid user session ID. The URI for this servlet is "/app?action=home".

Example 14-2 Cache ID for home servlet

<cache-id>
	<component id="action" type="parameter">
		<value>home</value>
		<required>true</required>
	</component>			
	<component id="JSESSIONID" type="cookie">
		<required>true</required>
	</component>	
</cache-id>	

3. Two dependency IDs are specified for the home servlet: Account_UserID and Holdings_UserID. Both IDs are used to identify user accounts by the UserID. The home servlet is session dependent and Account_UserID is used to invalidate the home servlet when either LoginCommand or LogoutCommand are invoked. Additionally, Holdings_UserID is used by OrderCompletedCommand to invalidate the home servlet upon the order completion. This is shown in Example 14-3. See also Cache replication testing.

Example 14-3 Dependency IDs for home servlet

<dependency-id>Account_UserID
	<component id="action" type="parameter" ignore-value="true">
		<value>home</value>
		<required>true</required>
	</component>
	<component id="uidBean" type="session">
		<required>true</required>
	</component>
</dependency-id>
<dependency-id>Holdings_UserID
	<component id="action" type="parameter" ignore-value="true">
		<value>home</value>
		<required>true</required>
	</component>
	<component id="uidBean" type="session">
		<required>true</required>
	</component>
</dependency-id>

4. A new cache entry is defined for the marketSummary.jsp, which is included by tradehome.jsp, which formats output from the home servlet command. The marketSummary.jsp can be invalidated based on time value (time-driven) or based on the update of data, which are rendered by marketSummary.jsp (event-driven). The ResetTradeCommand invalidates marketSummary.jsp using MarketSummary dependency ID.

Example 14-4 Cache entry for marketSummary.jsp

<cache-entry>
<class>servlet</class>
	<name>/marketSummary.jsp</name>
	<cache-id>
		<priority>3</priority>
		<timeout>180</timeout>
	</cache-id>
	<dependency-id>MarketSummary
	</dependency-id>
</cache-entry>

  Prev | Home | Next

 

WebSphere is a trademark of the IBM Corporation in the United States, other countries, or both.

 

IBM is a trademark of the IBM Corporation in the United States, other countries, or both.