![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
2
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
3
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
等都对其有支持,下面简单介绍一下OSCache的配置和使用过程。
1.安装过程
从http://www.opensymphony.com/oscache/download.html下载合适的OSCache版本,我下载的是oscache-2.3.1版本。解压缩下载的文件到指定目录,从解压缩目录取得oscache-2.3.1.jar文件放到 /WEB-INF/lib 或相应类库目录 ,从src或etc目录取得oscache.properties 文件,放入src根目录或发布环境的/WEB-INF/classes 目录,
如你需要建立磁盘缓存,须修改oscache.properties 中的cache.path信息 (去掉前面的#注释)。
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
2
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
2.oscache.properties 文件配置向导
cache.memory值为true 或 false ,默认为在内存中作缓存,如设置为false,那cache只能缓存到数据库或硬盘中,那cache还有什么意义:)
cache.capacity : 缓存元素个数
cache.persistence.class : 持久化缓存类,如此类打开,则必须设置cache.path信息
cache.cluster 相关 : 为集群设置信息。如
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
2
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
3.OSCache的基本用法
cache1.jsp 内容如下
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
2
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
3
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
4
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
5
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
6
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
7
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
8
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
9
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
10
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
11
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
12
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
13
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
14
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
15
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
16
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
cache2.jsp 执行手动刷新页面如下
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
2
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
3
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
4
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
5
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
6
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
7
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
8
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
你也可以通过下面语句定义Cache的有效范围,如不定义scope,scope默认为Applcation
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
2
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/9b8a8a44dd1c74ae49c20a7cd451974e.gif)
3
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
4. 缓存过滤器 CacheFilter
你可以在web.xml中定义缓存过滤器,定义特定资源的缓存。
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
2
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
3
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
4
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
5
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
6
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
7
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
8
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
9
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
10
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
11
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
12
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
13
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
14
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
15
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
16
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
17
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
18
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
19
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
上面定义将缓存所有.jsp页面,缓存刷新时间为60秒,缓存作用域为Session
注意:
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
2
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)
3
![OSCache使用指南 OSCache使用指南](https://i-blog.csdnimg.cn/blog_migrate/4f1150b881333f12a311ae9ef34da474.gif)