Tutorials > Dynamic caching > Accept cache identifiers
Accept 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.
Procedure
- Add a component for a session component, called sessionParam to the TopCategoriesDisplay page.
- Open the cachespec.xml file located at WC_EAR\Stores.war\WEB-INF.
- Add the following component to the <cache-id> for the TopCategoriesDisplay page:
<component 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_EAR\Stores.war
- Have the exercise4.jsp add a value for sessionParam to the session.
- Test the cachespec.xml again.
- Clear the cache.
- Hit http://localhost/webapp/wcs/stores/servlet/exercise4.jsp. The value sessionParam will now exist in the 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 the session.
- Reset the cachespec.xml.
- Remove the sessionParam component from the cachespec, or set the <required> flag to false for this component.