- 浏览: 83687 次
- 性别:
- 来自: 广州
最新评论
-
nanjiwubing123:
头像是java之父。
AJAX中文乱码解决 -
nanjiwubing123:
不错 ,解决了问题。
AJAX中文乱码解决 -
nao000:
感谢您的帖子带给的帮助。
上传文件类型验证工具类 -
KevinGarnett:
这里为什么用\\: 而不是用\: 是因为:是非标准转义字符, ...
jQuery 特殊字符应该使用转义 -
gongmingwind:
写的非常好,多谢多谢
Struts1x项目开发中的统一异常处理
OSCache标记库由OpenSymphony设计,它是一种开创性的JSP定制标记应用,提供了在现有JSP页面之内实现快速内存缓冲的功能。 OSCache是个一个广泛采用的高性能的J2EE缓存框架,OSCache能用于任何Java应用程序的普通的缓存解决方案。
使用方法:
1、拷贝oscache的jar包到web项目的lib下。
2、在WEB-INF下添加oscache的tld文件,oscache.tld
3、在web.xml文件中注册 oscache.tld
4、在src下添加文件 oscache.properties
5、页面使用缓存标签 test.jsp
6、移除缓存的数据(数据有更新时)
OSCacheHandler.java
完毕,进行应用测试。
使用方法:
1、拷贝oscache的jar包到web项目的lib下。
2、在WEB-INF下添加oscache的tld文件,oscache.tld
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"> <taglib> <tlib-version>1.6</tlib-version> <jsp-version>1.2</jsp-version> <short-name>oscache</short-name> <uri>http://www.opensymphony.com/oscache</uri> <display-name>OSCache Tag Library</display-name> <description>OSCache - see http://www.opensymphony.com/oscache</description> <tag> <name>cache</name> <tag-class>com.opensymphony.oscache.web.tag.CacheTag</tag-class> <body-content>JSP</body-content> <description>A tag to cache post-processed JSP contents</description> <attribute> <name>time</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>duration</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>cron</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>refreshpolicyclass</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>refreshpolicyparam</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>scope</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>refresh</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>mode</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>key</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>groups</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>language</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <tag> <name>usecached</name> <tag-class>com.opensymphony.oscache.web.tag.UseCachedTag</tag-class> <description>A tag to tell the cache to use the cached version</description> <attribute> <name>use</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <tag> <name>flush</name> <tag-class>com.opensymphony.oscache.web.tag.FlushTag</tag-class> <description>A tag to flush the cache</description> <attribute> <name>scope</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>key</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>group</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>language</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>pattern</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <tag> <name>addgroup</name> <tag-class>com.opensymphony.oscache.web.tag.GroupTag</tag-class> <description>A tag to add a group to an ancestor cache tag</description> <attribute> <name>group</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <tag> <name>addgroups</name> <tag-class>com.opensymphony.oscache.web.tag.GroupsTag</tag-class> <description>A tag to add a comma-delimited list of groups to an ancestor cache tag</description> <attribute> <name>groups</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib>
3、在web.xml文件中注册 oscache.tld
<!-- 注册标签函数 --> <jsp-config> <!-- oscache web应用缓存 --> <taglib> <taglib-uri>oscache</taglib-uri> <taglib-location>/WEB-INF/oscache.tld</taglib-location> </taglib> </jsp-config>
4、在src下添加文件 oscache.properties
cache.capacity=1000
5、页面使用缓存标签 test.jsp
<%@ taglib uri="oscache" prefix="cache" %> //... <cache:cache key="key1" time="-1"> //要缓存的内容 </cache:cache>
6、移除缓存的数据(数据有更新时)
OSCacheHandler cacheUtil = new OSCacheHandler(request,Constants.OSCACHE_APPLICATION); cacheUtil.remove(key);//key="key1"
OSCacheHandler.java
package cn.changtusoft.publicplatform.util.oscache; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.PageContext; import cn.changtusoft.publicplatform.service.common.SystemException; import com.opensymphony.oscache.base.Cache; import com.opensymphony.oscache.web.ServletCacheAdministrator; /** * oscache web应用缓存的操作类 * */ public class OSCacheHandler { private ServletCacheAdministrator admin = null; /** * A cache group. If specified, all content in that group will be flushed */ String group = null; /** * Tag key. */ String key = null; /** * if pattern value is specified, all keys that contain the pattern are * flushed. */ String pattern = null; String scope = null; int cacheScope = -1; /** * The ISO-639 language code to distinguish different pages in application * scope. */ private String language = null; private HttpServletRequest request; public void setScope(String value) { if (value != null) { if (value .equalsIgnoreCase(ServletCacheAdministrator.SESSION_SCOPE_NAME)) { cacheScope = PageContext.SESSION_SCOPE; } else if (value .equalsIgnoreCase(ServletCacheAdministrator.APPLICATION_SCOPE_NAME)) { cacheScope = PageContext.APPLICATION_SCOPE; } } } public ServletCacheAdministrator getAdmin() { return admin; } public void setAdmin(ServletCacheAdministrator admin) { this.admin = admin; } public int getCacheScope() { return cacheScope; } public void setCacheScope(int cacheScope) { this.cacheScope = cacheScope; } public String getScope() { return scope; } public String getGroup() { return group; } public void setGroup(String group) { this.group = group; } public String getPattern() { return pattern; } public void setPattern(String pattern) { this.pattern = pattern; } public String getLanguage() { return language; } public void setLanguage(String language) { this.language = language; } public HttpServletRequest getRequest() { return request; } public void setRequest(HttpServletRequest request) { this.request = request; } private static final long serialVersionUID = 2005659972627911969L; public OSCacheHandler(HttpServletRequest request, String scope) { this.request = request; if (admin == null) admin = ServletCacheAdministrator.getInstance(request.getSession() .getServletContext()); setScope(scope); } // 删除被缓存的对象; public void remove(String key) { if (group != null) // We're flushing a group { if (cacheScope >= 0) { Cache cache = admin.getCache(request, cacheScope); cache.flushGroup(group); } else { throw new SystemException( "A cache group was specified for flushing, but the scope wasn't supplied or was invalid"); } } else if (pattern != null) // We're flushing keys which contain the // pattern { if (cacheScope >= 0) { Cache cache = admin.getCache(request, cacheScope); cache.flushPattern(pattern); } else { throw new SystemException( "A pattern was specified for flushing, but the scope wasn't supplied or was invalid"); } } else if (key == null) // we're flushing a whole scope { if (cacheScope >= 0) { admin.setFlushTime(cacheScope); } else { admin.flushAll(); } } else // we're flushing just one key { if (cacheScope >= 0) { String actualKey = admin.generateEntryKey(key, request, cacheScope, null); Cache cache = admin.getCache(request, cacheScope); cache.flushEntry(actualKey); } else { throw new SystemException( "A cache key was specified for flushing, but the scope wasn't supplied or was invalid"); } } } }
完毕,进行应用测试。
发表评论
-
Java Thread Tech
2015-03-16 00:11 535user thread / daemon threadja ... -
Java Thread Tech
2015-03-16 00:10 0user thread / daemon threadjava ... -
移动支付-微信支付,中国银行支付交互图
2015-03-07 11:30 697以下是自己在做移动支付服务端时,画的支付交互时序图 ... -
OSCache页面缓存应用
2010-02-22 19:29 0OSCache页面缓存应用 -
上传文件类型验证工具类
2010-02-01 16:46 24341、定义合法文件类型的配置文件 allowuploadfil ... -
Tomcat访问地址映射配置
2010-01-08 09:42 4815实现的结果如: http://localhost: ... -
Compass对搜索关键字实现高亮显示
2010-01-07 08:49 1825例如搜"广东",实现后输出结果如 ... -
assert 是什么?
2010-01-04 00:04 1514assertion(断言)在软件开发中是一种常用的 ... -
struts2+spring+hibernate整合的一些配置文件,方便查找使用
2010-01-01 14:19 2704web.xml <?xml version=&quo ... -
struts2+spring+hibernate+compass 实现全文检索
2009-12-31 09:12 4146Compass是一流的开放源码JAVA搜索引擎框架,对 ... -
java序列化是什么,如何实现java序列化?
2009-12-30 08:50 1229序列化就是一种用来处理对象流的机制,所谓对象流也就 ... -
J2EE中一些常用的名词
2009-12-29 08:58 855web容器:给处于其中的应用程序组件(JSP,SERVLET) ... -
数据连接池的工作机制
2009-12-28 10:01 1280J2EE服务器启动时会建立一定数量的池连接,并一直 ... -
使用jspSmartUpload轻松实现上传和下载
2009-11-05 09:06 1130jspSmartUpload是由www.jspsm ... -
Struts2与Struts1的对比(推荐)
2009-11-03 22:24 7351、Action 类: Struts1要 ... -
定好项目规范的重要性
2009-11-02 23:28 1059近几个月都在忙于一个项目,由于需求的不明确,开始做的时 ... -
优秀java开源论坛 JForum,轻松搭建自己的论坛
2009-09-30 11:49 1476JForum 是一个功能强大 ,易于管理的论坛。它的 ... -
FreeMarker中文学习笔记
2009-09-24 17:09 714FreeMarker中文学习笔记。 -
多条件搜索的抽象实现
2009-09-24 17:02 0ColumnFields ColumnField -
Hibernate OneToOne双向关联为什么没有外键的一方不能Lazy加载?
2009-08-25 21:08 1665关联关系映射通常情况是比较难配置正确的。我觉得真正要掌握 ...
相关推荐
这里结合 天气预报的webservice 展示了OsCache框架的具体使用方法 项目可直接运行 ,代码简洁清晰
oscache-java缓存框架插件和安装教程,使用教程一步到位
OSCache缓存框架的简单用法,希望对大家有所帮助!!!
oscache缓存技术,压缩包中有详细代码及步骤
oscache缓存技术入门实例
描述了oscahce在JAVA开发中的应用和配置说明
oscache缓存使用总结
oscache,java,缓存机制的使用
OSCache是一个广泛采用的高性能的J2EE缓存框架,OSCache能用于任何Java应用程序的普通的缓存解决方案。 OSCache有以下特点:缓存任何对象,你可以不受限制的缓存部分jsp页面或HTTP请求,任何java对象都可以缓存。...
OSCache和Ehcache应用介绍,主要对页面缓存、服务器缓存相关应用的介绍
缓存框架oscache 的使用实例和详细解释,
Cache是一种用于提高系统响应速度、改善系统运行性能的技术。尤其是在Web应用中,通过缓存页面的输出...OSCache是个一个被广泛采用的高性能的J2EE缓存框架,OSCache还能应用于任何Java应用程序的普通的缓存解决方案。
OSCache标记库由OpenSymphony设计,它是一种开创性的缓存方案,它提供了在现有JSP页面之内实现内存缓存...OSCache是个一个被广泛采用的高性能的J2EE缓存框架,OSCache还能应用于任何Java应用程序的普通的缓存解决方案。
Hibernate OSCache缓存 Hibernate OSCache缓存
OSCache是个一个广泛采用的高性能的J2EE缓存框架,OSCache能用于任何Java应用程序的普通的缓存解决方案。OSCache有以下特点:缓存任何对象,你可以不受限制的缓存部分jsp页面或HTTP请求,任何java对象都可以缓存。 ...
Cache是一种用于提高系统响应速度、改善系统运行性能的技术。尤其是在Web应用中,通过缓存页面的...OSCache是个一个被广泛采用的高性能的J2EE缓存框架,OSCache还能应用于任何Java应用程序的普通的缓存解决方案。。。。
javaweb做页面缓存常用,OSCache是一个工业级的J2EE缓存实现。OSCache不但能缓存java对象,还可以缓存页面,http请求和二进制内容,例如pdf文件等。通过应用OSCache,我们不但可以实现通常的Cache功能,还能够改善...
oscache的使用
OSCache是个一个被广泛采用的高性能的J2EE缓存框架,OSCache还能应用于任何Java应用程序的普通的缓存解决方案。 OSCache是当前运用最广的缓存方案,JBoss,Hibernate,Spring等都对其有支持。 Oscache的使用非常方便,...
使用oscache进行缓存,大大提高web系统运行效率