用Ehcache进行页面数据缓存

首先当然是jar包了。将ehcache-web-2.0.3.jar 、ehcache-core-2.3.0.jar  拷入lib中。

下载地址:

Ehcache 对象、数据缓存:http://ehcache.org/downloads/destination?name=ehcache-core-2.5.2-distribution.tar.gz&bucket=tcdistributions&file=ehcache-core-2.5.2-distribution.tar.gz

Web页面缓存:http://ehcache.org/downloads/destination?name=ehcache-web-2.0.4-distribution.tar.gz&bucket=tcdistributions&file=ehcache-web-2.0.4-distribution.tar.gz

接着就是配置文件,在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>
       ......


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值