了解一下java系统中的OSCache配置
2012-02-21 18:24
615 查看
转载于:http://hi.baidu.com/wader2006/blog/item/0965a18bdc3d117e9f2fb435.html
最近一朋友说到系统的架构是Velocity+Hibernate,中间控制层是用servlet,其中用到了OSCache作为缓存系统!
现在我们来先了解一下OSChache的功能:
OSCache is a caching solution that includes a JSP tag library and set of classes to perform fine grained dynamic caching of JSP content, servlet responses or arbitrary objects. It provides both in memory and persistent on disk
caches, and can allow your site to have graceful error tolerance (eg if an error occurs like your db goes down, you can serve the cached content so people can still surf the site almost without knowing). Take a look at the great
features of OSCache.
features:
Fast in-memory caching/Persistent on-disk caching/Excellent Performance
Clustering support/Flexible Caching System/Simple JSP Tag Library
Caching Filter/Comprehensive API/Exception Handling/Cache Flushing
Portable caching/i18n Aware/Solid Reputation
现在来看看OSCache的配置过程:
从http://www.opensymphony.com/oscache下载合适的OSCache版本;(oscache-2.3.2-full)
从解压缩目录取得oscache.jar 文件放到 /WEB-INF/lib 或相应类库目录中;
如果你的jdk版本为1.3.x,建议在lib中加入Apache Common Lib 的commons-collections.jar包,jdk是1.4以上则不必;
从src或etc目录取得oscache.properties 文件,放入src根目录或发布环境的/WEB-INF/classes 目录;
如你需要建立磁盘缓存,须修改oscache.properties 中的cache.path信息 (去掉前面的#注释);
拷贝OSCache标签库文件oscache.tld到/WEB-INF/classes目录;
web.xml加入下列代码
<taglib>
<taglib-uri>oscache</taglib-uri>
<taglib-location>/WEB-INF/classes/oscache.tld</taglib-location>
</taglib>
oscache.properties 文件配置:
cache.memory:true 或 false ,默认为在内存中作缓存;
cache.capacity :缓存元素个数;
cache.persistence.class:持久化缓存类,如此类打开,则必须设置cache.path信息;
cache.cluster:集群设置信息;
cache.cluster.multicast.ip为广播IP地址;
cache.cluster.properties为集群属性;
OSCache的基本用法:(略)
======================cache1.jsp 内容如下=================
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.util.*" %>
<%@ taglib uri="oscache" prefix="cache" %>
<html>
<body>
没有缓存的日期: <%= new Date() %><p>
<!--自动刷新-->
<cache:cache time="30">
每30秒刷新缓存一次的日期: <%= new Date() %> <p>
</cache:cache>
<!--手动刷新-->
<cache:cache key="testcache">
手动刷新缓存的日期: <%= new Date() %> <p>
</cache:cache>
<a href="cache2.jsp">手动刷新</a>
</body>
</html>
=========================================================
====================cache2.jsp 执行手动刷新页面如下===========
<%@ page contentType="text/html;charset=GBK"%>
<%@ taglib uri="oscache" prefix="cache" %>
<html>
<body>缓存已刷新...<p>
<cache:flush key="testcache" scope="application"/>
<a href="cache1.jsp">返回</a>
</body>
</html>
==========================================================
缓存过滤器 CacheFilter:
在web.xml中定义缓存过滤器;参数如下:
<filter>
<filter-name>CacheFilter </filter-name>
<display-name>CacheFilter </display-name>
<description>CacheFilter </description>
<filter-class>com.opensymphony.oscache.web.filter.CacheFilter </filter-class>
<init-param>
<param-name>time </param-name>
<param-value>60 </param-value>
</init-param>
<init-param>
<param-name>scope </param-name>
<param-value>session </param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CacheFilter </filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
定义将缓存所有.jsp页面,缓存刷新时间为60秒,缓存作用域为Session,注意,CacheFilter只捕获Http头为200的页面请求,即只对无错误请求作缓存;而不对其他请求(如500,404,400)作缓存处理
最近一朋友说到系统的架构是Velocity+Hibernate,中间控制层是用servlet,其中用到了OSCache作为缓存系统!
现在我们来先了解一下OSChache的功能:
OSCache is a caching solution that includes a JSP tag library and set of classes to perform fine grained dynamic caching of JSP content, servlet responses or arbitrary objects. It provides both in memory and persistent on disk
caches, and can allow your site to have graceful error tolerance (eg if an error occurs like your db goes down, you can serve the cached content so people can still surf the site almost without knowing). Take a look at the great
features of OSCache.
features:
Fast in-memory caching/Persistent on-disk caching/Excellent Performance
Clustering support/Flexible Caching System/Simple JSP Tag Library
Caching Filter/Comprehensive API/Exception Handling/Cache Flushing
Portable caching/i18n Aware/Solid Reputation
现在来看看OSCache的配置过程:
从http://www.opensymphony.com/oscache下载合适的OSCache版本;(oscache-2.3.2-full)
从解压缩目录取得oscache.jar 文件放到 /WEB-INF/lib 或相应类库目录中;
如果你的jdk版本为1.3.x,建议在lib中加入Apache Common Lib 的commons-collections.jar包,jdk是1.4以上则不必;
从src或etc目录取得oscache.properties 文件,放入src根目录或发布环境的/WEB-INF/classes 目录;
如你需要建立磁盘缓存,须修改oscache.properties 中的cache.path信息 (去掉前面的#注释);
拷贝OSCache标签库文件oscache.tld到/WEB-INF/classes目录;
web.xml加入下列代码
<taglib>
<taglib-uri>oscache</taglib-uri>
<taglib-location>/WEB-INF/classes/oscache.tld</taglib-location>
</taglib>
oscache.properties 文件配置:
cache.memory:true 或 false ,默认为在内存中作缓存;
cache.capacity :缓存元素个数;
cache.persistence.class:持久化缓存类,如此类打开,则必须设置cache.path信息;
cache.cluster:集群设置信息;
cache.cluster.multicast.ip为广播IP地址;
cache.cluster.properties为集群属性;
OSCache的基本用法:(略)
======================cache1.jsp 内容如下=================
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.util.*" %>
<%@ taglib uri="oscache" prefix="cache" %>
<html>
<body>
没有缓存的日期: <%= new Date() %><p>
<!--自动刷新-->
<cache:cache time="30">
每30秒刷新缓存一次的日期: <%= new Date() %> <p>
</cache:cache>
<!--手动刷新-->
<cache:cache key="testcache">
手动刷新缓存的日期: <%= new Date() %> <p>
</cache:cache>
<a href="cache2.jsp">手动刷新</a>
</body>
</html>
=========================================================
====================cache2.jsp 执行手动刷新页面如下===========
<%@ page contentType="text/html;charset=GBK"%>
<%@ taglib uri="oscache" prefix="cache" %>
<html>
<body>缓存已刷新...<p>
<cache:flush key="testcache" scope="application"/>
<a href="cache1.jsp">返回</a>
</body>
</html>
==========================================================
缓存过滤器 CacheFilter:
在web.xml中定义缓存过滤器;参数如下:
<filter>
<filter-name>CacheFilter </filter-name>
<display-name>CacheFilter </display-name>
<description>CacheFilter </description>
<filter-class>com.opensymphony.oscache.web.filter.CacheFilter </filter-class>
<init-param>
<param-name>time </param-name>
<param-value>60 </param-value>
</init-param>
<init-param>
<param-name>scope </param-name>
<param-value>session </param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CacheFilter </filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
定义将缓存所有.jsp页面,缓存刷新时间为60秒,缓存作用域为Session,注意,CacheFilter只捕获Http头为200的页面请求,即只对无错误请求作缓存;而不对其他请求(如500,404,400)作缓存处理
相关文章推荐
- Windows8中查看硬件系统的基本配置了解一下配置情况
- WIN10 JAVA环境变量配置——几经辗转又重装了系统,分享一下Java环境变量的配置
- Java mac系统下JDK安装和环境变量的配置
- Java系统环境变量配置
- java基础讲解01-----简单了解一下java
- Windows系统环境下Solr之Java实战(一)搭建solr服务器并配置IK分词
- centos7 系统下HADOOP和Java 的环境配置
- Java开发环境jdk 1.8安装配置方法(Win7 64位系统/windows server 2008)
- JAVA 获取系统参数配置
- 使用java系统属性user.dir读取配置文件
- 系统的java 切换到自己配置的java
- 畅思大讲堂第二课:全方位的了解一下BI系统
- MAC系统下的环境变量配置java、android、maven
- 前2天后台系统需要生成报表,正好抽时间复习了一下之前做过的JAVA生成EXCEL,下面介绍POI 和JXL 生成报表的2种方式。
- 系统学习JavaWeb之特别篇使用注解WebServlet配置Servlet报404错误的原因
- 去哪网实习总结:windows下配置JavaWeb环境、开发helloworld、发布系统(附截图,绝对详细)(JavaWeb)
- java起步—jdk的下载和安装以及环境的配置(windows 7或者其他的系统)
- centos7 系统下HADOOP和Java 的环境配置
- java JDK 1.7配置系统系统变量
- sigar在Centos和Windows下使用java系统软硬件配置信息