http://www.opensymphony.com/oscache/download.html
https://java.net/downloads/oscache/OSCache%202.4/
可以参考学习一下官方的实例
下载实例与jar包
(1)获取oscache.properties文件,放在工程src目录下,可配置缓存基本属性(如:缓存开关等)
(2)在jsp中使用oscache缓存标签
<%--在jsp中导入标签--%>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%--使用标签:--%>
<cache:cache key="test" refresh="false" scope="application" time="10">
需要缓存的Jsp内容
</cache:cache>
标签说明(在oscache-example.war中都有体现):
Key:表示缓存内容的关键词。在指定的作用范围必须是唯一的。默认的key是被访问页面的URI和后面的亲球字符串
Scope:缓存发送的作用范围,可以是application或者session,默认application
Time:缓存时间段,单位秒,默认3600秒,设置负数缓存内容将永远不过期。
Duration:缓存失效时间
Refresh:设置为true时,缓存内容会被刷新,这边方便程序员设置更新条件。
Mode:如果编程者不希望被缓存的内容添加到给用户响应中,可以设置属性为”silent”
cache:cache中groups属性可定义缓存组,用于控制多个相同组的缓存是否同步刷新
cache:cache中cron属性,指定时间刷新缓存
(3)在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>20</param-value>
</init-param>
<init-param>
<param-name>scope</param-name>
<param-value>session</param-value>
</init-param>
<!—指定拦截请求类型 -- >
<init-param>
<param-name>disableCacheOnMethods</param-name>
<param-value>POST,PUT,DELETE</param-value>
</init-param>
<!—指定oscache配置文件 -- >
<init-param>
<param-name>oscache-properties-file</param-name>
<param-value>/oscache-cachefilter-disableCacheOnMethods.properties</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CacheFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>