Tutorial: Building cache identifiers >
< Previous | Next >

 

Building cache identifiers using cookies


The use of cookies does limit this component to Web-specific scenarios. You cannot use this component with other protocols, such as webservices.

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

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

    2. Add the following component to the <cache-id> for the TopCategoriesDisplay page
      <component  id="cookieComponent" type="cookie">
              <required>true</required>
              </component>
      
      
      

  2. Test the cachespec.xml.

    1. Use the cache monitor, look at the cache policies to verify that cookieComponent 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 there is no cookie named cookieComponent, there should not be an entry in the cache for TopCategoriesDisplay.

  3. Add the cookieComponent cookie. You will modify the jsp from Step 2 to do this.

    1. Open the file exercise4.jsp in: WC_eardir\Stores.war

    2. Add the following to the exercise4.jsp file
      <%@ page language="java" %>
      
      <HTML>
      <%
              Cookie mycookie = new
      Cookie("cookieComponent","helloWorld");
              response.addCookie(mycookie);
      %>
              <BODY>
                      <h1>Setting the cookie</h1>
      
              </BODY>
      
      </HTML>
      
      
      

  4. Test the cachespec.xml again.

    1. Clear your cache.

    2. Hit http://localhost/webapp/wcs/stores/servlet/exercise4.jsp. The cookieComponent cookie now exists.

    3. Hit the TopCategoriesDisplay page.

    4. Look at the cached entries in the cache monitor. There is an entry in the cache for TopCategoriesDisplay .

  5. Reset your cachespec.xml.

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


< Previous | Next >