`
sacredlove
  • 浏览: 11776 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

OSCache

阅读更多
使用OSCache进行简单的缓存
      在目前流行的三种开源的缓存工具中,OSCache的配置和使用应给是最简单的了,它主要是针对页面级的配置,EHCache主要针对对象级的缓存,MemCached应该是比较完整的了。接下来我们简单的讲一下在你的系统中怎样快速的应用上OSCache。只需简单的两步。
     第一步:加载oscache.properties文件,默认放到src目录下。下面是oscache.xml的默认配置。你只需简单的去掉一些注释就可以用了。
# CACHE IN MEMORY
#
# If you want to disable memory caching, just uncomment this line.
#
# cache.memory=false


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

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

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

# CACHE PERSISTENCE CLASS
#
# Specify the class to use for persistence. If you use the supplied DiskPersistenceListener,
# don't forget to supply the cache.path property to specify the location of the cache
# directory.
#
# If a persistence class is not specified, OSCache will use memory caching only.
#
# cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener
# cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.HashDiskPersistenceListener
# CACHE OVERFLOW PERSISTENCE
# Use persistent cache in overflow or not. The default value is false, which means
# the persistent cache will be used at all times for every entry.  true is the recommended setting.
#
# cache.persistence.overflow.only=true
# CACHE DIRECTORY
#
# This is the directory on disk where caches will be stored by the DiskPersistenceListener.
# it will be created if it doesn't already exist. Remember that OSCache must have
# write permission to this directory.
#
# Note: for Windows machines, this needs \ to be escaped
# ie Windows:
# cache.path=c:\\myapp\\cache
# or *ix:
# cache.path=/opt/myapp/cache
#
# cache.path=c:\\app\\cache

# CACHE ALGORITHM
#
# Default cache algorithm to use. Note that in order to use an algorithm
# the cache size must also be specified. If the cache size is not specified,
# the cache algorithm will be Unlimited cache.
#
# cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache
# cache.algorithm=com.opensymphony.oscache.base.algorithm.FIFOCache
# cache.algorithm=com.opensymphony.oscache.base.algorithm.UnlimitedCache
# THREAD BLOCKING BEHAVIOR
#
# When a request is made for a stale cache entry, it is possible that another thread is already
# in the process of rebuilding that entry. This setting specifies how OSCache handles the
# subsequent 'non-building' threads. The default behaviour (cache.blocking=false) is to serve
# the old content to subsequent threads until the cache entry has been updated. This provides
# the best performance (at the cost of serving slightly stale data). When blocking is enabled,
# threads will instead block until the new cache entry is ready to be served. Once the new entry
# is put in the cache the blocked threads will be restarted and given the new entry.
# Note that even if blocking is disabled, when there is no stale data available to be served
# threads will block until the data is added to the cache by the thread that is responsible
# for building the data.
#
# cache.blocking=false
# CACHE SIZE
#
# Default cache size in number of items. If a size is specified but not
# an algorithm, the cache algorithm used will be LRUCache.
#
cache.capacity=1000

# CACHE UNLIMITED DISK
# Use unlimited disk cache or not. The default value is false, which means
# the disk cache will be limited in size to the value specified by cache.capacity.
#
# cache.unlimited.disk=false

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

# JAVAGROUPS CLUSTER PROPERTIES
#
# Configuration properites for the JavaGroups clustering. Only one of these
# should be specified. Default values (as shown below) will be used if niether
# property is set. See the clustering documentation and the JavaGroups project
# (www.javagroups.com) for more information on these settings.
#
#cache.cluster.properties=UDP(mcast_addr=231.12.21.132;mcast_port=45566;ip_ttl=32;\
#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


第二步:在web.xml进行一些简单的配置,oscache提供了强大的标签。主要是针对jsp的,如果项目中需把oscache.tld放到WEB-INF/classes下,在再web.xml中配置一下。

<!--oscache taglib  -->
<jsp-config>
  <taglib>
   <taglib-uri>oscache</taglib-uri>
   <taglib-location>
    /WEB-INF/classes/oscache.tld
   </taglib-location>
  </taglib>
</jsp-config>
在jsp中应用的话,还需简单的引入。<%@ taglib uri="oscache" prefix="cache" %>
具体的应用:<cache:cache key="testcache"></cache:cache>。
    以上是针对具体的页面的配置步骤。如果想针对某一页面的类型进行配置,可以利用过滤器来配置。比如我们想对以*.ftl和*.jsp的页面进行缓存的话,我们只需这样简单的配置在web.xml中。
<!-- OScacheFilter  -->
<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>3600</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>*.ftl</url-pattern>
</filter-mapping>
<filter-mapping>
  <filter-name>CacheFilter</filter-name>
  <url-pattern>*.jsp</url-pattern>
</filter-mapping>
<!-- OScacheFilter  -->

如果想对某一访问的路径action进行缓存的话,我们可以这样做,在一个jsp文件中简单的加上:
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib uri="oscache" prefix="cache" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>My JSP 'index.jsp' starting page</title>
</head>
<body>
  <oscache:cache>
   <jsp:include page ="/view.do"/>
  </oscache:cache>
</body>
</html>
分享到:
评论

相关推荐

    OSCache配置说明文档

    OSCache由OpenSymphony设计,它是一种开创性的JSP定制标记应用,提供了在现有JSP页面之内实现快速内存缓冲的功能。OSCache是一个广泛采用的高性能的J2EE缓存框架,OSCache能用于任何Java应用程序的普通的缓存解决...

    oscache(JSP定制标记应用)

    javaweb做页面缓存常用,OSCache是一个工业级的J2EE缓存实现。OSCache不但能缓存java对象,还可以缓存页面,http请求和二进制内容,例如pdf文件等。通过应用OSCache,我们不但可以实现通常的Cache功能,还能够改善...

    oscache-2.1.jar

    oscache-2.1.jar oscache-2.1.jar

    oscache-2.4.1-full.rar

    、OSCache是什么? OSCache标记库由OpenSymphony设计,它是一种开创性的缓存方案,它提供了在现有JSP页面之内实现内存缓存的功能。OSCache是个一个被广泛采用的高性能的J2EE缓存框架,OSCache还能应用于任何Java...

    oscache的例子

    OSCache标记库由OpenSymphony设计,它是一种开创性的缓存方案,它提供了在现有JSP页面之内实现内存缓存的功能。OSCache是个一个被广泛采用的高性能的J2EE缓存框架,OSCache还能应用于任何Java应用程序的普通的缓存...

    oscache缓存技术入门实例

    oscache缓存技术入门实例

    OSCache学习例子 实例

    OSCache学习例子 实例 很好的与j2ee结合

    oscache文档

    OSCache标记库由OpenSymphony设计,它是一种开创性的JSP定制标记应用,提供了在现有JSP页面之内实现快速内存缓冲的功能。OSCache是个一个广泛采用的高性能的J2EE缓存框架,OSCache能用于任何Java应用程序的普通的...

    用OSCache进行缓存对象

    1、OSCache是什么? 2、OSCache的特点 3、有关“用OSCache进行缓存对象”的研究

    oscache jar包下载

    oscache-2.4.1.jar资源包,用于java缓存、jsp页面缓存

    Oscache使用手册

    Cache是一种用于提高系统响应速度、改善系统运行性能的技术。尤其是在Web应用中,通过缓存页面的...OSCache是个一个被广泛采用的高性能的J2EE缓存框架,OSCache还能应用于任何Java应用程序的普通的缓存解决方案。。。。

    Oscache框架的搭建步骤

    使用oscache进行缓存,大大提高web系统运行效率

    oscache 使用介紹

    OSCache是OpenSymphony这个开源项目众多Projects中的一个。他是一个高效的J2EE缓存框架,能够很好的解决动态网站速度的问题。

    oscache-java缓存框架

    oscache-java缓存框架插件和安装教程,使用教程一步到位

    OSCache需要的包

    oscache.tld,oscahe.properties,oscache-2.1.jar,commons

    oscache所需jar包

    commons-logging.jar包 oscache-2.4.1.jar包 oscache-2.4.1.jar

    oscache的使用实例和详解

    缓存框架oscache 的使用实例和详细解释,

    oscache-2.3.jar

    oscache-2.3.jar

    缓存技术 oscache-2.3.2.jar包下载

    缓存技术 oscache-2.3.2.jar包下载

    oscache-2.4.jar

    oscache-2.4.jar osCache框架的jar文件,版本是2.4的噢! --------java爱好者 java交流群:166256747, 分享自己的技术是一种美德!

Global site tag (gtag.js) - Google Analytics