Ehcache 2.10.6 | Related Documentation | Web Cache User Guide | Sample web.xml Configuration | Example web.xml Configuration
 
Example web.xml Configuration
Following is a sample web.xml configuration file.
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
version="2.5">
<filter>
<filter-name>CachePage1CachingFilter</filter-name>
<filter-class>net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter
</filter-class>
<init-param>
<param-name>suppressStackTrace</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>cacheName</param-name>
<param-value>CachePage1CachingFilter</param-value>
</init-param>
</filter>
<filter>
<filter-name>SimplePageFragmentCachingFilter</filter-name>
<filter-class>
net.sf.ehcache.constructs.web.filter.SimplePageFragmentCachingFilter
</filter-class>
<init-param>
<param-name>suppressStackTrace</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>cacheName</param-name>
<param-value>SimplePageFragmentCachingFilter</param-value>
</init-param>
</filter>

<filter>
<filter-name>SimpleCachingHeadersPageCachingFilter</filter-name>
<filter-class>
net.sf.ehcache.constructs.web.filter.SimpleCachingHeadersPageCachingFilter
</filter-class>
<init-param>
<param-name>suppressStackTrace</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>cacheName</param-name>
<param-value>CachedPage2Cache</param-value>
</init-param>
</filter>

<!-- This is a filter chain. They are executed in the order below.
Do not change the order. -->

<filter-mapping>
<filter-name>CachePage1CachingFilter</filter-name>
<url-pattern>/CachedPage.jsp</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>

<filter-mapping>
<filter-name>SimplePageFragmentCachingFilter</filter-name>
<url-pattern>/include/Footer.jsp</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>SimplePageFragmentCachingFilter</filter-name>
<url-pattern>/fragment/CachedFragment.jsp</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>SimpleCachingHeadersPageCachingFilter</filter-name>
<url-pattern>/CachedPage2.jsp</url-pattern>
</filter-mapping>
An ehcache.xml configuration file, matching the above, would then be:
<Ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../main/config/ehcache.xsd">
<diskStore path="auto/default/path"/>
<defaultCache
maxEntriesLocalHeap="10"
eternal="false"
timeToIdleSeconds="5"
timeToLiveSeconds="10">
<persistence strategy="localTempSwap"/>
/>
<!-- Page and Page Fragment Caches -->
<cache name="CachePage1CachingFilter"
maxEntriesLocalHeap="10"
eternal="false"
timeToIdleSeconds="10000"
timeToLiveSeconds="10000">
<persistence strategy="localTempSwap"/>
</cache>
<cache name="CachedPage2Cache"
maxEntriesLocalHeap="10"
eternal="false"
timeToLiveSeconds="3600">
<persistence strategy="localTempSwap"/>
</cache>
<cache name="SimplePageFragmentCachingFilter"
maxEntriesLocalHeap="10"
eternal="false"
timeToIdleSeconds="10000"
timeToLiveSeconds="10000">
<persistence strategy="localTempSwap"/>
</cache>
<cache name="SimpleCachingHeadersTimeoutPageCachingFilter"
maxEntriesLocalHeap="10"
eternal="false"
timeToIdleSeconds="10000"
timeToLiveSeconds="10000">
<persistence strategy="localTempSwap"/>
</cache>
</ehcache>

Copyright © 2010-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.