https://oscache.dev.java.net/files/documents/629/13962/oscache-2.1.1-full.zip
OSCache各版本下载页面:http://www.opensymphony.com/oscache/download.action

○用二分钟配置:

将下载的oscache-2.1.1-full.zip解压,你会看到oscache-2.1.1.jar 及一些目录 docs、etc、lib、src。
现在将 etc目录下oscache.properties 、oscache.tld 及 oscache-2.1.1.jar 文件复制到你的应用服务器目录下

使用tomcat,jdk1.4 配置例:
         D:\Tomcat 5.0\webapps\ROOT\WEB-INF\lib\oscache-2.1.1.jar
         D:\Tomcat 5.0\webapps\ROOT\WEB-INF\classes\oscache.properties
         D:\Tomcat 5.0\webapps\ROOT\WEB-INF\classes\oscache.tld

oscache.properties 文件配置参数说明:
cache.memory
值为true 或 false ,默认为在内存中作缓存,
如设置为false,那cache只能缓存到数据库或硬盘中,那cache还有什么意义:)
cache.capacity
缓存元素个数
cache.persistence.class
持久化缓存类,如此类打开,则必须设置cache.path信息
cache.cluster 相关
为集群设置信息。如
cache.cluster.multicast.ip为广播IP地址
cache.cluster.properties为集群属性

再将 D:\Tomcat 5.0\webapps\ROOT\WEB-INF\web.xml 文件中添加如下代码
<taglib>
<taglib-uri>oscache</taglib-uri>
<taglib-location>/WEB-INF/classes/oscache.tld</taglib-location>
</taglib>

就是这么简单,OSCache就配置好了。

○再用二分钟测试一下

编写jsp文件
======================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="http://dev.csdn.net/article/"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="http://dev.csdn.net/article/"cache1.jsp">返回</a></body>
</html>
==========================================================       

其他: 缓存过滤器 CacheFilter
可以让你所有.jsp页面自动缓存。

你可以在web.xml中定义缓存过滤器,定义特定资源的缓存。
<filter>
<filter-name>CacheFilter</filter-name>
<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)作缓存处理

此文完。。谢谢观看。

posted on 2006-09-08 17:57 jackstudio 阅读(584) 评论(1)  编辑  收藏 所属分类: commonjava

只有注册用户登录后才能发表评论。


网站导航: