项目中用到OSCache来实现jsp页面缓存功能的杂谈

本人是一新手,项目中用到OSCache来实现jsp页面缓存功能,自己大概总结了一下,有不足之处,请大家别见笑!
1.jsp页面中定义。
<%@ taglib uri="oscache" prefix="cache" %>

...要缓存的部分...

2.web.xml中定义。

oscache
/WEB-INF/classes/oscache.tld

3.oscache.tld
......
cache
com.opensymphony.oscache.web.tag.CacheTag
JSP
........
4.用的是oscache-2.1.jar
放在你的应用服务器lib\目录下或你的应用程序\WEB-INF\lib\下
注意的地方:
有cache的地方,session就不能用了。
搜索页面部分不要用cache,每个人搜索的内容都不一样的。
关键子的定义,每个页面的关键子当然都不一样的,另外如果有分页,得把分页参数取得,放入关键字里,(不然的话,每页内容都一样了),如果还有其他的传入参数,比如查看不同分类,会有不同分类的ID,也要放到关键字里。
执行一次JSP,而后在设定的时间内,客户端访问的都是HTML页面。

小弟是一新手,大家见笑了!

1.jsp页面中定义。
《%@ taglib uri="oscache" prefix="cache" %》
《cache:cache key="关键字" time="300" scope="application"》
...要缓存的部分...
《/cache:cache》
2.web.xml中定义。
《taglib》
《taglib-uri》oscache《/taglib-uri》
《taglib-location》/WEB-INF/classes/oscache.tld《/taglib-location》
《/taglib》
3.oscache.tld
......
《name》cache《/nam》
《tag-class》com.opensymphony.oscache.web.tag.CacheTag《/tag-class》
《body-content》JSP《/body-content》
........
非常不错,贴代码时,选择上方的Code即可。
在web.xml中,配置OScache拦截时,好像只能是*.jsp,如果是*就出错。
好兴奋,感谢斑竹的肯定,以后我会把工作中的经验发到这里,和大家一起分享!大家共同进步!
我在一个门户网站中就全面用到了OSCACHE缓存系统,我感觉还是不错的。

搂住说的功能,是实现内存缓存方式。另外一种就是磁盘缓存,可以在OSCACHE配置文件中,指定磁盘物理目录,系统运行后,就会把缓存的页面,全部以文件形式存储在目录中。后者一般是针对内存不足以够的情况下使用。

缓存的数据每30分钟自动刷新数据,这是默认的。可以在WEB。XML中指定刷新时间,也可以手工刷新。


另外,OSCache还支持集群功能.

磁盘缓存实现:

oscache.properties


<strong>CACHE IN MEMORY</strong>
<strong># If you want to disable memory caching, just uncomment this line.</strong>
<strong>cache.memory=false</strong>


<strong>CACHE KEY </strong>
<strong># This is the key that will be used to store the cache in the application</strong>
<strong>and session scope.</strong>
<strong># If you want to set the cache key to anything other than the default</strong>
<strong>uncomment this line and change the cache.key</strong>
<strong># cache.key=__oscache_cache</strong>


<strong>USE HOST DOMAIN NAME IN KEY</strong>
<strong># Servers for multiple host domains may wish to add host name info to</strong>
<strong>the generation of the key. If this is true, then uncomment the</strong>
<strong>following line.</strong>
<strong># cache.use.host.domain.in.key=true</strong>


<strong>CACHE LISTENERS</strong>
<strong># These hook OSCache events and perform various actions such as logging</strong>
<strong>cache hits and misses, or broadcasting to other cache instances across a cluster.</strong>
<strong>See the documentation for further information.</strong>
<strong># cache.event.listeners=com.opensymphony.oscache.plugins.clustersupport.JMSBroadcastingListener, \</strong>
<strong>com.opensymphony.oscache.extra.CacheEntryEventListenerImpl, \</strong>
<strong>com.opensymphony.oscache.extra.CacheMapAccessEventListenerImpl, \</strong>
<strong>com.opensymphony.oscache.extra.ScopeEventListenerImpl</strong>


<strong>CACHE PERSISTENCE CLASS</strong>
<strong># Specify the class to use for persistence. If you use the supplied DiskPersistenceListener,</strong>
<strong>don't forget to supply the cache.path property to specify the location of the cache</strong>
<strong>directory.</strong>
<strong># If a persistence class is not specified, OSCache will use memory caching only.</strong>
<strong>#cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.HashDiskPersistenceListener</strong>
cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.HashDiskPersistenceListener
<strong>CACHE OVERFLOW PERSISTENCE</strong>
<strong>Use persistent cache in overflow or not. The default value is false, which means</strong>
<strong>the persistent cache will be used at all times for every entry. true is the recommended setting.</strong>
<strong>#cache.persistence.overflow.only=false</strong>

<strong>CACHE DIRECTORY</strong>
<strong># This is the directory on disk where caches will be stored by the DiskPersistenceListener.</strong>
<strong>it will be created if it doesn't already exist. Remember that OSCache must have</strong>
<strong>write permission to this directory.</strong>
<strong># Note: for Windows machines, this needs \ to be escaped</strong>
<strong>ie Windows:</strong>
<strong>cache.path=c:\\myapp\\cache</strong>
<strong>or *ix:</strong>
<strong>cache.path=/opt/myapp/cache</strong>
<strong>cache.path=F:\\jboss-3.2.1\\server\\default\\deploy\\weihai.war\\powercache</strong>


<strong>CACHE ALGORITHM</strong>
<strong># Default cache algorithm to use. Note that in order to use an algorithm</strong>
<strong>the cache size must also be specified. If the cache size is not specified,</strong>
<strong>the cache algorithm will be Unlimited cache.</strong>
<strong>cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache</strong>
<strong>cache.algorithm=com.opensymphony.oscache.base.algorithm.FIFOCache</strong>
<strong>cache.algorithm=com.opensymphony.oscache.base.algorithm.UnlimitedCache</strong>

<strong>THREAD BLOCKING BEHAVIOR</strong>
<strong># When a request is made for a stale cache entry, it is possible that another thread is already</strong>
<strong>in the process of rebuilding that entry. This setting specifies how OSCache handles the</strong>
<strong>subsequent 'non-building' threads. The default behaviour (cache.blocking=false) is to serve</strong>
<strong>the old content to subsequent threads until the cache entry has been updated. This provides</strong>
<strong>the best performance (at the cost of serving slightly stale data). When blocking is enabled,</strong>
<strong>threads will instead block until the new cache entry is ready to be served. Once the new entry</strong>
<strong>is put in the cache the blocked threads will be restarted and given the new entry.</strong>
<strong>Note that even if blocking is disabled, when there is no stale data available to be served</strong>
<strong>threads will block until the data is added to the cache by the thread that is responsible</strong>
<strong>for building the data.</strong>
cache.blocking=true


<strong>CACHE SIZE</strong>
<strong># Default cache size in number of items. If a size is specified but not</strong>
<strong>an algorithm, the cache algorithm used will be LRUCache.</strong>
cache.capacity=4000



<strong>CACHE UNLIMITED DISK ??????????????????1000??????????1000???LRU?????????????????</strong>
<strong>Use unlimited disk cache or not. The default value is false, which means</strong>
<strong>the disk cache will be limited in size to the value specified by cache.capacity.</strong>
cache.unlimited.disk=true



<strong>JMS CLUSTER PROPERTIES</strong>
<strong># Configuration properties for JMS clustering. See the clustering documentation</strong>
<strong>for more information on these settings.</strong>
<strong>#cache.cluster.jms.topic.factory=java:comp/env/jms/TopicConnectionFactory</strong>
#cache.cluster.jms.topic.name=java:comp/env/jms/OSCacheTopic
#cache.cluster.jms.node.name=node1


<strong>JAVAGROUPS CLUSTER PROPERTIES</strong>
<strong># Configuration properites for the JavaGroups clustering. Only one of these</strong>
<strong>should be specified. Default values (as shown below) will be used if niether</strong>
<strong>property is set. See the clustering documentation and the JavaGroups project</strong>
<strong>(www.javagroups.com) for more information on these settings.</strong>
<strong>#cache.cluster.properties=UDP(mcast_addr=231.12.21.132;mcast_port=45566;ip_ttl=32;\</strong>
#mcast_send_buf_size=150000;mcast_recv_buf_size=80000):\
#PING(timeout=2000;num_initial_members=3):\
#MERGE2(min_interval=5000;max_interval=10000):\
#FD_SOCK:VERIFY_SUSPECT(timeout=1500):\
#pbcast.NAKACK(gc_lag=50;retransmit_timeout=300,600,1200,2400,4800;max_xmit_size=8192):\
#UNICAST(timeout=300,600,1200,2400):\
#pbcast.STABLE(desired_avg_gossip=20000):\
#FRAG(frag_size=8096;down_thread=false;up_thread=false):\
#pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true)
#cache.cluster.multicast.ip=231.12.21.132
如果企业有钱的话,就不推荐使用OSCache....
他们可以去买网站内容管理,这样就可以生成静态页面了.

.OSCache无非就是减轻服务器压力....

请问 OSCACHE 中 缓存的作用范围
APPLICATION SESSION
到底该怎么选择 是什么意思
> 请问 OSCACHE 中 缓存的作用范围
> APPLICATION SESSION
> 到底该怎么选择 是什么意思

这样看情况了,如果是Portal系统,大多数页面对于大多数人来说是一样的,那么使用Application,如果是MIS系统,将涉及数据权限,用JSP缓存的意义并不大,一般是采用对象缓存.

再请问下
OSCACHE对 JSP部分内容的缓存


<%
//自己的JSP代码内容
%>

标签之间是否可包含其他的标签
比如STRUTS的

再请问下
OSCACHE对 JSP部分内容的缓存



<cache:cache key="foobar" scope="session">
<%
//自己的JSP代码内容
%>
</cache:cache>


标签之间是否可包含其他的标签
比如STRUTS的

如果我的应用是采用STRUTS模式,几乎所有的JSP都是通过.do的方式跳转,那么用OSCACHE是否有效,我考虑在ACTION里来CACHE,但是研究了一天,对一般对象可以,但是如果是采用类的反射机制取得的LIST,putincache和getfromcache的值是空,不知道什么原因,大家可以研究一下
小弟现在做一个项目,想用OS Cache做业务层的部分数据的缓存,不知道用OS Cache能不能做,具体的思路是什么样的,麻烦高人指点一二。
从功能来讲,oscache是个可用的缓存。
从性能来讲,oscache缓存的性能很差


从性能来讲,oscache缓存的性能很差

性能很差?那方面?

内存使用太大? 命中率太低?