Tutorials > Dynamic caching > Accept cache identifiers

< Previous | Next >


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

  1. Add a component for a session component, called sessionParam to the TopCategoriesDisplay page.

    1. Open the cachespec.xml file located at WC_EAR\Stores.war\WEB-INF.

    2. Add the following component to the <cache-id> for the TopCategoriesDisplay page:

      <component    type="session">
             
      <required>true</required>
             
      </component>
      

  2. Test the cachespec.xml.

    1. Use the cache monitor, look at the cache policies to verify that sessionParam is a required component of the cache-id.

    2. Use the cache monitor to clear the entries from the cache.

    3. Hit the TopCategoriesDisplay page.

    4. 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.

  3. Add the sessionParam value to the session. You will create a JSP to do this.

    1. Create a file called exercise4.jsp in: WC_EAR\Stores.war

    2. Have the exercise4.jsp add a value for sessionParam to the session.

  4. Test the cachespec.xml again.

    1. Clear the cache.

    2. Hit http://localhost/webapp/wcs/stores/servlet/exercise4.jsp. The value sessionParam will now exist in the session

    3. Hit the TopCategoriesDisplay page.

    4. 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.

  5. Reset the cachespec.xml.

    1. Remove the sessionParam component from the cachespec, or set the <required> flag to false for this component.

< Previous | Next >


+

Search Tips   |   Advanced Search