Tutorials > Dynamic caching > Invalidate cache
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
- Create a cache-id for the CategoryDisplay pages.
- Open the cachespec.xml file located at WC_EAR\Stores.war\WEB-INF.
- 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>
- Create a dependency-id to identify the Kitchenware pages.
- 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>
- 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>
- Test the cachespec.xml.
In this tutorial, you learned to invalidate cache entries using dependency trees dynacache provides.
- Use the cache monitor to clear the cache.
- Hit the store, making sure to browse to the Kitchenware section, and visit some of its subcategories.
- Use the cache monitor, view the entries associated with the Kitchenware dependency-id.