Servlet Cache instance

By default when you use the servlet output caching it gets store in the default baseCache instance. But there could situations where you would want to use separate cache for your servlet for better control, may be because you want to cache content say across cluster or want to make sure that 2000 entries are stored in the cache or some other example. If thats the case then you can create a Servlet cache instance and configure your web application to use.

I made changes in DynaCacheSample to try this by first creating ServletInstanceOne cache instance using the WAS Admin Console at the cell level like this



Then i changed the cachespec.xml file in my web application to add cache-instance element with name equal to JNDI name of the cache instance that i just configured and making all the cache-entry elements as its child element. If you want you can create multiple cache instances and use one instance for each of the cache entry. My cachespec.xml looks like this


<?xml version="1.0" ?>
<!DOCTYPE cache SYSTEM "cachespec.dtd">
<cache>
<cache-instance name="services/cache/instance_one" >
<cache-entry>
<class>servlet</class>
<name>/dynacacheservlet</name>

<cache-id>
<component id="action" type="parameter">
<required>false</required>
</component>
<timeout>180</timeout>
</cache-id>
</cache-entry>
<cache-entry>
<class>servlet</class>
<name>/dynachache.jsp</name>
<cache-id>
<component id="action" type="parameter">
<required>false</required>
</component>
<timeout>180</timeout>
</cache-id>
</cache-entry>
<cache-entry>
<class>static</class>
<name>com.ibm.ws.webcontainer.servlet.SimpleFileServlet.class</name>
<cache-id>
<component id="" type="pathinfo">
<required>true</required>
</component>
<component id="If-Modified-Since" type="header">
<required>false</required>
</component>
<timeout>300</timeout>
</cache-id>
</cache-entry>
</cache-instance>
</cache>


I did deploy the new application and try hitting the URL few times. Now when i use the CacheMonitor application i can see the services/cache/instance_one cache instance in it with the servlet content being stored in it like this

No comments: