您的位置:首页 > 运维架构 > 网站架构

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

2016-04-12 16:59 441 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: