1 下载地址 http://www.opensymphony.com/oscache/
2 把下载的jar 加入到你的build path 里面。 建议直接放到 tomcat/shared/lib 目录下面
3 在 web.xml 里面增加配置
<taglib> <taglib-uri>oscache</taglib-uri> <taglib-location>/WEB-INF/classes/oscache.tld</taglib-location> </taglib>
4 在你的JSP 页面里增加如下标签
<%@ taglib uri=\"http://www.opensymphony.com/oscache\" prefix=\"cache\"%>
5 在需要缓冲的部分,采用如下标签
<cache:cache key=\"myPageCachekey\" groups=\"myDefaultGroup\" scope=\"application\" time=\"1800\">。。。 这中间是你要缓冲的内容</cache:cache>
6 刷新缓冲
<cache:flush scope=\"application\" group=\"myDefaultGroup\" />
参数说明
key - [默认为请求的 request URI + query string] -
The cache key, any string. This should be unique for the given scope since
duplicate keys will map to the same cache entry. The default value uses an escaped
version of the URI and query string of the current page.
It is possible to specify multiple cache tags in the same page without specifying keys - in this situation an index is appended to the key of subsequent tags.
However this usage is discouraged since if the flow of the page is inconsistent,
or cache tags are nested, the indicies will potentially change each time the page is
executed, resulting in seemingly jumbled cache entries.
缓冲的key,可以是任何的字符串。在一个范围内是唯一的,因为相同的key代表了相同的缓冲入口。默认使用请求的URI和请求的字符串(问号后面的部分)
scope - [application] - The scope of this cache (valid values are \"application\" and \"session\").
范围,有application和session, 默认为 application
time - [3600] The amount of time to cache this content for (in second