This example puts all the steps together for configuring the dynamic cache with the cachespec.xml file, showing the use of the cache ID generation rules, dependency IDs, and invalidation rules.
Suppose that a servlet is used to manage a simple news site. This servlet uses the query parameter "action" to determine if the request is being used to "view" news or "update" news (used by the administrator). Another query parameter "category" is used to select the news category. Suppose that this site supports an optional customized layout that is stored in the user's session using the attribute name "layout". Here are example URL requests to this servlet:
http://yourhost/yourwebapp/newscontroller?action=view&category=sports (Returns a news page for the sports category )
http://yourhost/yourwebapp/newscontroller?action=view&category=money (Returns a news page for the money category)
http://yourhost/yourwebapp/newscontroller?action=update&category=fashion (Allows the administrator to update news in the fashion category)
Here are the steps for configuring dynamic cache for this example with the cachespec.xml file:
<cache-entry> <name> /newscontroller </name> <class>servlet </class> </cache-entry>
<cache-entry> <name> /newscontroller </name> <class>servlet </class> <cache-id> <component id="action" type="parameter"> <value>view</value> <required>true</required> </component> <component id="category" type="parameter"> <required>true</required> </component> <component id="layout" type="session"> <required>false</required> </component> </cache-id> </cache-entry>
<cache-entry> <name>newscontroller </name> <class>servlet </class> <cache-id> <component id="action" type="parameter"> <value>view</value> <required>true</required> </component> <component id="category" type="parameter"> <required>true</required> </component> <component id="layout" type="session"> <required>false</required> </component> </cache-id> <dependency-id>category <component id="category" type="parameter"> <required>true</required> </component> </dependency-id> </cache-entry>
<cache-entry> <name>newscontroller </name> <class>servlet </class> <cache-id> <component id="action" type="parameter"> <value>view</value> <required>true</required> </component> <component id="category" type="parameter"> <required>true</required> </component> <component id="layout" type="session"> <required>false</required> </component> </cache-id> <dependency-id>category <component id="category" type="parameter"> <required>true</required> </component> </dependency-id> <invalidation>category <component id="action" type="parameter" ignore-value="true"> <value>update</value> <required>true</required> </component> <component id="category" type="parameter"> <required>true</required> </component> </invalidation> </cache-entry>
Related tasks
Task overview: Using the dynamic cache service to improve performance
Configuring servlet caching
Verifying the cacheable page