j2ee页面静态化方案encache web cache框架详解1
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? 浏览器如果支持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的异常?
参考:http://www.ehcache.org/documentation/user-guide/web-caching
?
对源码实现欢迎参考 http://zhwj184.iteye.com/blog/1545157