Tutorial: Building cache identifiers >
< Previous | Next >
Building cache identifiers using method calls into the WebSphere Application
Cache-ids are composed from values that are in the WebSphere Application Server session. To access these values, specify a component type of session and use the value that is the name of the object in the session.
- Add a component for a session component, called sessionParam to the TopCategoriesDisplay page.
- Open the cachespec.xml file located at WC_eardir\Stores.war\WEB-INF.
- Add the following component to the <cache-id> for the TopCategoriesDisplay page
<component id="sessionParam" type="session"> <required>true</required> </component>
- Test the cachespec.xml.
- Use the cache monitor, look at the cache policies to verify that sessionParam is a required component of the cache-id.
- Use the cache monitor to clear the entries from the cache.
- Hit the TopCategoriesDisplay page.
- Look at the cached entries in the cache monitor. Because the value sessionParam does not exist in our session, there should not be an entry in the cache.
- Add the sessionParam value to the session. You will create a JSP to do this.
- Create a file called exercise4.jsp in: WC_eardir\Stores.war
- Have the exercise4.jsp add a value for sessionParam to the session.
- Test the cachespec.xml again.
- Clear your cache.
- Hit http://localhost/webapp/wcs/stores/servlet/exercise4.jsp. The value sessionParam will now exist in your session
- Hit the TopCategoriesDisplay page.
- Look at the cached entries in the cache monitor. There is an entry in the cache for TopCategoriesDisplay since there is now a value for sessionParam in your session.
- Reset your cachespec.xml.
- Remove the sessionParam component from the cachespec, or set the <required> flag to false for this component.