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存在,如果有,直接返回成功页面,如果没有则执行剩下的代码。

 

 

 

目录
相关文章
|
1月前
|
缓存 JavaScript
vue使用keep-alive实现页面前进刷新,后退缓存,完美运行无bug
vue使用keep-alive实现页面前进刷新,后退缓存,完美运行无bug
287 1
|
4月前
|
存储 缓存 监控
SpringBoot配置第三方专业缓存技术Ehcache
SpringBoot配置第三方专业缓存技术Ehcache
41 1
|
4月前
|
缓存 监控 负载均衡
Java一分钟之-Ehcache:分布式缓存系统
【6月更文挑战第17天】**Ehcache是Java的开源缓存库,支持本地和分布式缓存,提供负载均衡、数据复制和容错能力。常见问题包括网络分区导致的数据不一致、缓存雪崩和配置不当引起的性能瓶颈。解决策略涉及选择强一致性策略、设置合理缓存过期时间和监控调整配置。使用Ehcache需添加相关依赖,并配置分布式缓存,如示例所示,通过CacheManager创建和管理缓存。实践中,持续监控和优化配置至关重要。**
100 1
|
4月前
|
缓存 Java
修改缓存供应商--EhCache
修改缓存供应商--EhCache
|
5月前
|
存储 缓存 JavaScript
vue中缓存页面数据(刷新不丢失)
vue中缓存页面数据(刷新不丢失)
411 1
|
11月前
|
缓存 NoSQL Java
分布式系列教程(01) -Ehcache缓存架构
分布式系列教程(01) -Ehcache缓存架构
230 0
|
5月前
|
缓存 NoSQL Java
使用thymeleaf和Redis缓存实现秒杀系统页面静态化
使用thymeleaf和Redis缓存实现秒杀系统页面静态化
91 0
|
5月前
|
SQL 缓存 Java
Hibernate - 整合Ehcache二级缓存使用详解
Hibernate - 整合Ehcache二级缓存使用详解
64 0
|
存储 缓存 NoSQL
EhCache缓存
在查询数据的时候,数据大多来自数据库,通常会基于SQL语句的方式与数据库交互,数据库一般会基于本地磁盘IO的形式将数据读取到内存,返回给Java服务端,Java服务端再将数据响应给客户端,做数据展示。
122 0
|
缓存 NoSQL Java
SpringBoot-26-缓存Ehcache的使用
spring缓存(cache)是在Spring3.1开始引入的,但是其本身只提供了缓存接口,不提供具体缓存的实现,其实现需要第三方缓存实现(Generic、EhCache、Redis等)。EhCache、Redis比较常用,使用Redis的时候需要先安装Redis服务器。
93 0