码迷,mamicode.com
首页 > 系统相关 > 详细

EHCache页面缓存技术

时间:2015-09-06 14:46:15      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

EHCache的jar包 :http://ehcache.org/downloads/catalog     这里用的是EHcache的web包。


在项目的web.xml文件中加入一个filter:

<!--EHCache 页面缓存技术,该页面缓存技术用于page -> filter之间,若是局部页面缓存,
          则用SimplePageFragmentCachingFilter,但应注意局部页面要被其他页面 jsp:include
    -->
    <filter>
        <filter-name>indexCacheFilter</filter-name>
        <filter-class> net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter</filter-class>
    </filter>
    <!-- 这里是需要缓存的页面 -->
    <filter-mapping>
        <filter-name>indexCacheFilter</filter-name>
        <url-pattern>/index.jsp</url-pattern>
    </filter-mapping>



在src中新建一个ehcache.xml文件:

    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../main/config/ehcache.xsd">  
    <diskStore path="java.io.tmpdir/ehcache" />  
    
    
        <!-- 
            timeToIdleSeconds ,多长时间不访问该缓存,那么ehcache 就会清除该缓存
            timeToLiveSeconds ,缓存的存活时间,从开始创建的时间算起
            memoryStoreEvictionPolicy,采用哪种缓存算法
            overflowToDisk=true 意思是表示当缓存中元素的数量超过限制时,就把这些元素持久化到硬盘
            maxElementsInMemory 表示内存中SimplePageCachingFilter 缓存中元素的最大数量为10
            maxElementsOnDisk 是指持久化该缓存的元素到硬盘上的最大数量也为10
            eternal,缓存是否会死亡
         -->
        <cache name = "SimplePageCachingFilter"
                      maxElementsInMemory = "10"
                      maxElementsOnDisk = "10"
                      eternal = "false"
                      overflowToDisk = "true"
                      diskSpoolBufferSizeMB = "20"
                      timeToIdleSeconds = "120"
                      timeToLiveSeconds = "120"
                      memoryStoreEvictionPolicy = "LFU"/> 
    </ehcache>


ok,这样就对index.jsp做了缓存。另外,对于频繁更新的页面不应该使用缓存技术。

EHCache页面缓存技术

标签:

原文地址:http://my.oschina.net/u/2328736/blog/501680

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!