oscache缓存配置

来源:互联网 发布:首次提出大数据的时间 编辑:程序博客网 时间:2024/06/09 15:50

1.下载oscache:https://java.net/downloads/oscache/OSCache%202.4/oscache-2.4-full.zip

2..1  添加依赖包:oscache-2.4.jar、commons-logging.jar到classpath

2.2 添加配置文件:oscache.tld、oscache.properties到classpath

3.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>1</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>/*</url-pattern>    </filter-mapping>

3.1在需要使用缓存的页面添加缓存标签

index.jsp

<%@ page import="java.util.Date" %><%@ page contentType="text/html;charset=UTF-8" language="java" %><%@ taglib prefix="os" uri="http://www.opensymphony.com/oscache" %><html><head>    <title>ehcache demo</title></head><body>    <os:cache time="3">        <%= new Date()%>    </os:cache><br>    新的:<%= new Date()%></body></html>
4.oscache.properties 参数解释

#是否启用缓存,默认为truecache.memory=true        #设置缓存储存在那个域中,默认为application和session域cache.key=application        # 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.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 如果没有指定算法默认算法为LRUCachecache.capacity=1000        #是否允许无限的使用磁盘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



1 0
原创粉丝点击