首先当然是jar包了。将ehcache-web-2.0.3.jar 、ehcache-core-2.3.0.jar 拷入lib中。
下载地址:
接着就是配置文件,在src下新建ehcache.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true" monitoring="autodetect"
dynamicConfig="true">
<diskStore path="java.io.tmpdir"/>
<cache name="SimplePageFragmentCachingFilter"
maxElementsInMemory="10"
eternal="false"
timeToIdleSeconds="10000"
timeToLiveSeconds="10000"
overflowToDisk="true">
</cache>
</ehcache>
最后在web.xml中配置一下相应的过滤器(必须在Struts2的filter之前配置!)
<!-- 页面缓存配置 ehcache-->
<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-mapping>
<filter-name>SimplePageFragmentCachingFilter</filter-name>
<url-pattern>/index.action</url-pattern>
</filter-mapping>
备注:如果需要有多个url-pattern,就需要写多个<filter-mapping>
<filter-mapping>
....
</filter-mapping>
<filter-mapping>
....
</filter-mapping>
......