Tutorial: Invalidating cache >
< Previous

 

Invalidating cache using dependency trees


It is useful to create conceptual groupings of your cache-entries, and invalidate based on those groups. For example, consider the ConsumerDirect store - how can you invalidate all of the entries for a particular category or subcategory?
Use dependency-ids, it is possible to achieve this. In the example that follows, you will create a grouping for the Kitchenware pages.

  1. Create a cache-id for the CategoryDisplay pages.

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

    2. Add a cache-id for CategoryEntry to the cache-entry for the Request servlet. See below for what this cache-entry should contain.
      <cache-id>
              <component id="" type="pathinfo">
                      <required>true</required>
                      <value>/CategoryDisplay</value>
              </component>
              <component id="storeId" type="parameter">
                      <required>true</required>
              </component>
              <component id="catalogId" type="parameter">
                      <required>true</required>
              </component>
              <component id = "categoryId" type="parameter">
                      <required>true</required>
              </component>
      </cache-id>
      
      
      

  2. Create a dependency-id to identify the Kitchenware pages.

    1. Make a dependency-id to identify pages with categoryId=10003 as Kitchenware pages.
      <dependency-id>KitchenWare
              <component id="" ignore-value="true" type="pathinfo">
                      <required>true</required>
                      <value>/CategoryDisplay</value>
              </component>
              <component id="categoryId" ignore-value="true"
      type="parameter">
                      <required>true</required>omponent>
      </dependency-id> 
      
      
      

    2. You also need to create a dependency-id to identify the Kitchenware subcategory pages. Identify these pages by looking for parent_category_rn=10003.
      <dependency-id>KitchenWare
              <component id="" ignore-value="true" type="pathinfo">
                      <required>true</required>
                      <value>/CategoryDisplay</value>
              </component>
              <component id="parent_category_rn" ignore-value="true"
      type="parameter">
                      <required>true</required>
                      <value>10003</value>
              </component>
      </dependency-id>
      
      
      

  3. Test the cachespec.xml.

    1. Use the cache monitor to clear the cache.

    2. Hit the store, making sure to browse to the Kitchenware section, and visit some of its subcategories.

    3. Use the cache monitor, view the entries associated with the Kitchenware dependency-id.


Tutorial Summary In this tutorial, you learned to invalidate cache entries using dependency trees dynacache provides.
< Previous