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

 

 

 

目录
打赏
0
0
0
0
1
分享
相关文章
SpringBoot集成Ehcache缓存使用指南
以上是SpringBoot集成Ehcache缓存的基本操作指南,帮助你在实际项目中轻松实现缓存功能。当然,Ehcache还有诸多高级特性,通过学习和实践,你可以更好地发挥它的威力。
123 20
|
10月前
|
vue使用keep-alive实现页面前进刷新,后退缓存,完美运行无bug
vue使用keep-alive实现页面前进刷新,后退缓存,完美运行无bug
961 1
分布式系列教程(01) -Ehcache缓存架构
分布式系列教程(01) -Ehcache缓存架构
492 0
SpringBoot配置第三方专业缓存技术Ehcache
SpringBoot配置第三方专业缓存技术Ehcache
94 1
Java一分钟之-Ehcache:分布式缓存系统
【6月更文挑战第17天】**Ehcache是Java的开源缓存库,支持本地和分布式缓存,提供负载均衡、数据复制和容错能力。常见问题包括网络分区导致的数据不一致、缓存雪崩和配置不当引起的性能瓶颈。解决策略涉及选择强一致性策略、设置合理缓存过期时间和监控调整配置。使用Ehcache需添加相关依赖,并配置分布式缓存,如示例所示,通过CacheManager创建和管理缓存。实践中,持续监控和优化配置至关重要。**
271 1
使用thymeleaf和Redis缓存实现秒杀系统页面静态化
使用thymeleaf和Redis缓存实现秒杀系统页面静态化
159 0
Hibernate - 整合Ehcache二级缓存使用详解
Hibernate - 整合Ehcache二级缓存使用详解
109 0

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问