- 浏览: 738464 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
lgh1992314:
a offset: 26b offset: 24c offse ...
java jvm字节占用空间分析 -
ls0609:
语音实现在线听书http://blog.csdn.net/ls ...
Android 语音输入API使用 -
wangli61289:
http://viralpatel-net-tutorials ...
Android 语音输入API使用 -
zxjlwt:
学习了素人派http://surenpi.com
velocity宏加载顺序 -
tt5753:
谢啦........
Lucene的IndexWriter初始化时的LockObtainFailedException的解决方法
web caching
1.介绍
Ehcache Web 是 EhCache 缓存框架的一个组件,主要用于Java开发Web项目中的一些缓存功能。包括一个单页缓存过滤器:SimplePageCachingFilter;页面压缩(gzip)支持;页面片段缓存等功能。在某些情况下能够很好的提高web应用的性能。
2.simplePageCachingFilter
能够缓存httpresponse的html,json,xml等输出的完整页面或者页面片段的缓存,也支持gzipping的页面缓存。页面片段缓存可以参考SimplePageFragmentCachingFilter类。
3.keys 缓存的key值
缓存的key是依赖的查询url和query查询参数串,比如/admin/SomePage.jsp?id=1234&name=Beagle。不依赖于url的域名和端口号,所以对于绑定多个域名的同一台机器也是有效地。但是如果url加了一些为了跟踪用户行为用的序列生成的id号,则无法使用缓存。在这种情况下你也可以重写calculateKey(javax.servlet.http.HttpServletRequest)这个方法来定义自己缓存的key。
4.多线程并发缓存失效问题
为了避免多线程并发导致cache失效之类的问题,可以通过设置init-param的 blockingTimeoutMillis
参数,指定第一个获得锁的线程的超时时间,避免后续请求阻塞。
5.gzipping
浏览器如果支持Accept-Encoding: gzip,则在缓存中直接取出gzip的response结果,如果浏览器不支持,则cache会通过高效的ungzipped之后把结果输出到response上。
6.caching headers
SimpleCachingHeadersPageCachingFilter
这个类能够缓存http请求 headers的ETag, Last-Modified 和Expires字段,支持get请求。这样是为了让浏览器快速获取某个页面是否浏览器缓存失效问题。
7.web。xml中可以设置的 init-params
-
cacheName
-ehcache.xml 用户设置的filter的cache名称 -
blockingTimeoutMillis
- the time, in milliseconds, to wait for the filter chain to return with a response on a cache miss. This is useful to fail fast in the event of an infrastructure failure. -
varyHeader
- set to true to set Vary:Accept-Encoding in the response when doing Gzip. This header is needed to support HTTP proxies however it is off by default.
8.SimplePageFragmentCacheingFilter
跟simplePageCachingFilter差不多,不过不支持gzip,这样才能对多个页面进行合并。
9.web.xml的配置
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee version="2.5"> <filter> <filter-name>CachePage1CachingFilter</filter-name> <filter-class>net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter </filter-class> <init-param> <param-name>suppressStackTrace</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>cacheName</param-name> <param-value>CachePage1CachingFilter</param-value> </init-param> </filter> <filter> <filter-name>SimplePageFragmentCachingFilter</filter-name> <filter-class>net.sf.ehcache.constructs.web.filter.SimplePageFragmentCachingFilter </filter-class> <init-param> <param-name>suppressStackTrace</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>cacheName</param-name> <param-value>SimplePageFragmentCachingFilter</param-value> </init-param> </filter> <filter> <filter-name>SimpleCachingHeadersPageCachingFilter</filter-name> <filter-class>net.sf.ehcache.constructs.web.filter.SimpleCachingHeadersPageCachingFilter </filter-class> <init-param> <param-name>suppressStackTrace</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>cacheName</param-name> <param-value>CachedPage2Cache</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>CachePage1CachingFilter</filter-name> <url-pattern>/CachedPage.jsp</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping> <filter-mapping> <filter-name>SimplePageFragmentCachingFilter</filter-name> <url-pattern>/include/Footer.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>SimplePageFragmentCachingFilter</filter-name> <url-pattern>/fragment/CachedFragment.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>SimpleCachingHeadersPageCachingFilter</filter-name> <url-pattern>/CachedPage2.jsp</url-pattern> </filter-mapping>
10.ehcache.xml的配置
<Ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../main/config/ehcache.xsd"> <diskStore path="java.io.tmpdir"/> <defaultCache maxEntriesLocalHeap="10" eternal="false" timeToIdleSeconds="5" timeToLiveSeconds="10" overflowToDisk="true" /> <!-- Page and Page Fragment Caches --> <cache name="CachePage1CachingFilter" maxEntriesLocalHeap="10" eternal="false" timeToIdleSeconds="10000" timeToLiveSeconds="10000" overflowToDisk="true"> </cache> <cache name="CachedPage2Cache" maxEntriesLocalHeap="10" eternal="false" timeToLiveSeconds="3600" overflowToDisk="true"> </cache> <cache name="SimplePageFragmentCachingFilter" maxEntriesLocalHeap="10" eternal="false" timeToIdleSeconds="10000" timeToLiveSeconds="10000" overflowToDisk="true"> </cache> <cache name="SimpleCachingHeadersTimeoutPageCachingFilter" maxEntriesLocalHeap="10" eternal="false" timeToIdleSeconds="10000" timeToLiveSeconds="10000" overflowToDisk="true"> </cache> </ehcache>
11.caching filter的异常
FilterNonReentrantException 当同一个线程再次重入caching filter处理时抛出异常,因为当第一个请求还未block时,同一个线程再次进入该filter就会block
ResponseHeadersNotModifiableException类似FilterNonReentrantException
AlreadyGzippedException 如果已经对一个页面进行gzip处理,再次gzip时就抛出该异常
ResponseHeadersNotModifiableException如果对页面进行gzip处理,那么需要重新设置setheader的值,如果在设置过程中出错了,则抛出该异常。
参考:http://www.ehcache.org/documentation/user-guide/web-caching
对源码实现欢迎参考 http://zhwj184.iteye.com/blog/1545157
发表评论
-
对字符串进行验证之前先进行规范化
2013-09-17 23:18 13876对字符串进行验证之前先进行规范化 应用系统中经常对字 ... -
使用telnet连接到基于spring的应用上执行容器中的bean的任意方法
2013-08-08 09:17 1423使用telnet连接到基于spring的应用上执行容器中 ... -
jdk7和8的一些新特性介绍
2013-07-06 16:07 10063更多ppt内容请查看:htt ... -
Lucene的IndexWriter初始化时的LockObtainFailedException的解决方法
2013-06-28 21:35 11727原文链接: http://www.javaarch.net ... -
java对于接口和抽象类的代理实现,不需要有具体实现类
2013-06-12 09:50 2902原文链接:http://www.javaarch.net/j ... -
Excel2007格式分析和XML解析
2013-06-07 09:56 10605在物料清单采购中,用到excel上传文件解析功能,不 ... -
Java EE 7中对WebSocket 1.0的支持
2013-06-05 09:27 3794原文链接:http://www.javaarch.n ... -
java QRCode生成示例
2013-06-05 09:26 1459原文链接:http://www.javaarch.n ... -
Spring Security Logout
2013-06-03 00:05 2317原文地址:http://www.javaarch.net/ ... -
Spring Security Basic Authentication
2013-06-03 00:04 1690原文地址:http://www.javaarch.net/ ... -
Spring Security Form Login
2013-06-02 16:16 2107原文地址:http://www.javaarch.net/j ... -
spring3 的restful API RequestMapping介绍
2013-06-02 14:53 1112原文链接:http://www.javaarch.net/j ... -
Java Web使用swfobject调用flex图表
2013-05-28 19:05 1074Java Web使用swfobject调用 ... -
spring使用PropertyPlaceholderConfigurer扩展来满足不同环境的参数配置
2013-05-21 15:57 3283spring使用PropertyPlaceholderCon ... -
java国际化
2013-05-20 20:57 4432java国际化 本文来自:http://www.j ... -
RSS feeds with Java
2013-05-20 20:52 1181RSS feeds with Java 原文来自:htt ... -
使用ibatis将数据库从oracle迁移到mysql的几个修改点
2013-04-29 10:40 1627我们项目在公司的大战略下需要从oracle ... -
线上机器jvm dump分析脚本
2013-04-19 10:48 2854#!/bin/sh DUMP_PIDS=`p ... -
spring3学习入门示例工程
2013-04-18 09:28 10831. github地址 https://github ... -
spring map使用annotation泛型注入问题分析
2013-04-15 13:30 8498今天在整一个spring的ioc学习demo,碰到 ...
相关推荐
encache缓存
压缩包里有encache-1.1.jar encache-1.3.jar encache-1.5.jar三个jar包
ENCACHE缓存简介 ENCACHE缓存简介 ENCACHE缓存简介 ENCACHE缓存简介
里面有两个xsd文件,springmodules-ehcache和springmodules-cache.xsd。需求:因为有时候在你在xml中用某个标签时,提示错误,有时候就是少了xsd的引入
包含encache.jar,encache.core.jar,encache.web.jar还有源码
使用Encache进行缓存存取的工具类,java中使用,配置好配置文件就可以使用
SpringWeb 架构(Maven+SpringMVC+SpringJDBC+Apache Shiro+Redis+MongoDB+EnCache+Freemarker+JSP)定位架构,借助Springside框架,好资源多分享
包含Redis,memcache,encache的NoSQL入门
spring、 spring mvc、 hibernate、 ehcache JavaWeb后台框架
JGroups是一个开源的纯java编写的可靠的群组通讯工具。其工作模式基于IP多播,但可以在可靠性和群组成员管理上进行扩展。其结构上设计灵活,提供了一种灵活兼容多种协议的协议栈。
网上找的cache集群的例子 博文链接:https://tjbmx0987.iteye.com/blog/916394
在网上找了很久的jar包,要不就是少这个,要不就是少那个,这次一次性收集全
J2Cache 使用Ceffien作为一级缓存,使用Redis作为二级缓存时的配置
代码是Ehcache的页面缓存、spring的缓存和Hibernate的缓存的应用,采用的是springMVC框架,数据库是MySQL
NULL 博文链接:https://ligf06.iteye.com/blog/1710893
主要讲解下encache的原理、分布式缓存集群环境配置、与在spring中的使用
NULL 博文链接:https://miaoxianjie.iteye.com/blog/1704619
一看就懂的ehcache缓存技术使用技巧
使用ehcahe时自己做的工具类,方便以后使用
springboot2.0、Mybatis-Plus、encache...... Typora 1、热部署: org.springframework.boot spring-boot-devtools true idea默认是没有自动编译的,我们这里需要添加修改配置.打开设置 (1)File-Settings-...