使用oscache提升网站速度

王朝java/jsp·作者佚名  2006-01-10
宽屏版  字体: |||超大  

oscache是opensymphony社区提供的一款优秀的缓存框架。据说是目前应用范围最广的。详细介绍可见http://www.opensymphony.com/oscache/

A caching solution that includes a JSP tag library and set of classes to perform fine grained dynamic caching of JSP content,

servlet responses or arbitrary objects. It provides both in memory and persistent on disk caches, and can allow your site

to have graceful error tolerance (eg if an error occurs like your db goes down, you can serve the cached content so people

can still surf the site almost without knowing).

csdn社区中也有人介绍了oscache的基本安装和使用:http://blog.csdn.net/ezerg/archive/2004/10/15/135769.aspx

在这里介绍一点自己的使用心得。首次体验出oscache的强大,是在作第一版的xyzp.net时,其中首页左边的导航栏对数据库进行了70多次操作,为了提高性能,这里使用了oscache的tag标签,进行了永久性缓存,即如果不手工更新,这里将永远不变化,达到了只进行一批数据库操作的效果。速度的提升很明显。代码如下:

<cache:cache key="leftmenu" scope="application" time="-1"> 要缓存的内容 </cache:cache>

效果图:

实际的运行效果,由于网站已经改版,可以通过baidu的cache查看。

在网站第二次改版时,采用了oscache提供的页面级缓存。对数据库操作的网页都进行了缓存。缓存时间设定为25分钟,在这段时间内,访问特定的网页都会被定向到缓存页面。几乎达到了静态网页的效果;)

代码如下:在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>1200</param-value>

</init-param>

<init-param>

<param-name>scope</param-name>

<param-value>application</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>CacheFilter</filter-name>

<url-pattern>/×.html</url-pattern>

</filter-mapping>

注:本网站采用spring框架,网页的后缀名按管理采用.html。

实际的运行效果大家可以查看 校园招聘一网打尽 http://www.xyzp.net

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有