Tutorials > Dynamic caching > Invalidate cache

< Previous


Invalidate cache using dependency trees

It is useful to create conceptual groupings of the 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, we will create a grouping for the Kitchenware pages.


Procedure

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

    1. Open the cachespec.xml file located at WC_EAR\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  type="pathinfo">
                     
      <required>true</required>
                     
      <value>/CategoryDisplay</value>
             
      </component>
             
      <component  type="parameter">
                     
      <required>true</required>
             
      </component>
             
      <component  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  ignore-value="true" type="pathinfo">
                     
      <required>true</required>
                     
      <value>/CategoryDisplay</value>
             
      </component>
             
      <component  ignore-value="true" type="parameter">
                     
      <required>true</required>
                     
      <value>10003</value>
             
      </component>
      </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  ignore-value="true" type="pathinfo">
                     
      <required>true</required>
                     
      <value>/CategoryDisplay</value>
             
      </component>
             
      <component  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.
    In this tutorial, you learned to invalidate cache entries using dependency trees dynacache provides.

< Previous


+

Search Tips   |   Advanced Search