网站首页添加缓存--------ehcache的简单使用

1、首先把jar包放g以lib目录下ehcache-core-2.4.3.jar,ehcache-web-2.0.4.jar

2、在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="false" dynamicConfig="false">
    <diskStore path="java.io.tmpdir/ehcache"/>
    <cache name = "SimplePageCachingFilter"
           maxElementsInMemory = "10"
           maxElementsOnDisk = "10"
           eternal = "false"
           overflowToDisk = "true"
           diskSpoolBufferSizeMB = "20"  
           timeToIdleSeconds = "300"
           timeToLiveSeconds = "300"
           memoryStoreEvictionPolicy = "LFU"
            >
        </cache>
    
</ehcache>
3、在web.xml中进行配置

     <welcome-file-list>
    <welcome-file>OnLoadServlet</welcome-file>
  </welcome-file-list>

<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>/OnLoadServlet</url-pattern>
    </filter-mapping>

 

 <servlet>
    <servlet-name>OnLoadServlet</servlet-name>
    <servlet-class>com.dianzhi.qiantai.servlet.OnLoadServlet</servlet-class>
  </servlet>

 

 <servlet-mapping>
    <servlet-name>OnLoadServlet</servlet-name>
    <url-pattern>/OnLoadServlet</url-pattern>
  </servlet-mapping>

posted @ 2016-04-12 16:59  赤子之心_timefast  阅读(231)  评论(0编辑  收藏  举报