s2sh整合ehcache页面部分缓存

简介: 先记一下,blogjava上不了。 ehcache做页面部分缓存,配置有点麻烦,操作也有点复杂,不过感觉还是很好用。 首先看web.xml配置: 增加以下配置: <!--ehcache web page cache --> <filter> <filter-name>fragmentCache</filter-name>

先记一下,blogjava上不了。

ehcache做页面部分缓存,配置有点麻烦,操作也有点复杂,不过感觉还是很好用。

首先看web.xml配置:

增加以下配置:

<!--ehcache web page cache --> <filter> <filter-name>fragmentCache</filter-name> <filter-class>net.sf.ehcache.constructs.web.filter.SimplePageFragmentCachingFilter </filter-class> <init-param> <param-name>suppressStackTraces</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>cacheName</param-name> <param-value>fragmentCache</param-value> </init-param> </filter> <!-- This is a filter chain. They are executed in the order below. Do not change the order. --> <filter-mapping> <filter-name>fragmentCache</filter-name> <url-pattern>/WEB-INF/pages/tour/tourDetailBody.jsp</url-pattern> <dispatcher>INCLUDE</dispatcher> </filter-mapping>

注意,那个<dispatcher>INCLUDE</dispatcher>,不能少,少了缓存不能用。

配置中对应<jsp:include page="/WEB-INF/pages/tour/tourDetailBody.jsp"/>

 

 

2.4版本的servlet规范在部属描述符中新增加了一个<dispatcher>元素,这个元素有四个可能的值:即REQUEST,FORWARD,INCLUDE和ERROR,可以在一个<filter-mapping>元素中加入任意数目的<dispatcher>,使得filter将会作用于直接从客户端过来的request,通过forward过来的request,通过include过来的request和通过<error-page>过来的request。如果没有指定任何< dispatcher >元素,默认值是REQUEST。

 

<?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../main/config/ehcache.xsd"> <diskStore path="java.io.tmpdir" /> <defaultCache maxElementsInMemory="10" eternal="false" timeToIdleSeconds="5" timeToLiveSeconds="10" overflowToDisk="true" /> <!-- maxElementsInMemory="10"内存中的最大页面对象 eternal="false" timeToIdleSeconds="120" timeToIdleSeconds ,多长时间不访问该缓存,那么ehcache就会清除该缓存。 timeToLiveSeconds="240" timeToLiveSeconds,缓存的存活时间,从开始创建的时间算起。 overflowToDisk="true" 是否写入硬盘 --> <!-- Page and Page Fragment Caches --> <cache name="fragmentCache" maxElementsInMemory="10" eternal="false" timeToIdleSeconds="10000" timeToLiveSeconds="10000" overflowToDisk="true"> </cache> </ehcache>

数据的更新问题:

和页面缓存一样的,根据配置文件中的cacheName获取Ehcache,再根据获取的key进行remove操作。

 

action中的问题:当页面请求发生时,会调用action方法,这时我们因为先方法,应该先查询cache中是否有缓存fragment存在,如果有,直接返回成功页面,如果没有则执行剩下的代码。

 

 

 

目录
相关文章
|
5月前
|
缓存 NoSQL Java
分布式系列教程(01) -Ehcache缓存架构
分布式系列教程(01) -Ehcache缓存架构
97 0
|
3月前
|
缓存 NoSQL Java
使用thymeleaf和Redis缓存实现秒杀系统页面静态化
使用thymeleaf和Redis缓存实现秒杀系统页面静态化
50 0
|
7月前
|
存储 缓存 NoSQL
EhCache缓存
在查询数据的时候,数据大多来自数据库,通常会基于SQL语句的方式与数据库交互,数据库一般会基于本地磁盘IO的形式将数据读取到内存,返回给Java服务端,Java服务端再将数据响应给客户端,做数据展示。
71 0
|
8月前
|
缓存 NoSQL Java
SpringBoot-26-缓存Ehcache的使用
spring缓存(cache)是在Spring3.1开始引入的,但是其本身只提供了缓存接口,不提供具体缓存的实现,其实现需要第三方缓存实现(Generic、EhCache、Redis等)。EhCache、Redis比较常用,使用Redis的时候需要先安装Redis服务器。
66 0
|
8月前
|
缓存 Java 数据库连接
什么是EhCache 缓存
什么是EhCache 缓存
71 0
|
10月前
|
XML 缓存 Java
|
10月前
|
存储 缓存 NoSQL
Java Cache 缓存方案详解及代码-Ehcache
Java Cache 缓存方案详解及代码-Ehcache
399 0
|
11月前
|
XML 缓存 安全
MyBatis-24MyBatis缓存配置【集成EhCache】
MyBatis-24MyBatis缓存配置【集成EhCache】
68 0
|
缓存 前端开发
ehcache jgroups同步,节点重启初始化缓存bug
ehcache jgroups同步,节点重启初始化缓存bug
114 0

热门文章

最新文章