您的位置:首页 > 其它

HibernateEhcacheJgroups - 基于Annotation的集群缓存配置

2014-04-01 21:35 429 查看
一、版本相关

    ehcache-jgroupsreplication-1.7.jar

    jgroups-3.4.1.Final.jar

    ehcache-core-2.6.5.jar

    hibernate3.6.10.Final.jar

二、EhCache ehcache.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true" monitoring="autodetect" dynamicConfig="true">

<diskStore path="E:/WS/temp/ehcahe" />

<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
properties="connect=UDP(mcast_addr=230.0.0.1;mcast_port=45566;tos=32;mcast_recv_buf_size=120000;loopback=true;
mcast_send_buf_size=80000;discard_incompatible_packets=true;max_bundle_size=64K;max_bundle_timeout=30;
ip_ttl=32;enable_bundling=true;enable_diagnostics=true;thread_naming_pattern=cl;timer.min_threads=4;
timer_type=new;timer.max_threads=10;timer.keep_alive_time=3000;timer.queue_max_size=500;thread_pool.enabled=true;
thread_pool.min_threads=2;thread_pool.max_threads=8;thread_pool.keep_alive_time=5000;oob_thread_pool.keep_alive_time=5000;
thread_pool.queue_enabled=true;thread_pool.queue_max_size=10000;thread_pool.rejection_policy=discard;
oob_thread_pool.enabled=true;oob_thread_pool.min_threads=1;oob_thread_pool.max_threads=8;
oob_thread_pool.queue_enabled=false;oob_thread_pool.queue_max_size=100;oob_thread_pool.rejection_policy=Run):
PING(timeout=2000;num_initial_members=6):
MERGE2(min_interval=5000;max_interval=10000):
VERIFY_SUSPECT(timeout=1500):
pbcast.NAKACK(use_mcast_xmit=true;discard_delivered_msgs=true;retransmit_timeout=1200):
UNICAST(timeout=1200):
pbcast.STABLE(desired_avg_gossip=20000;stability_delay=1000;max_bytes=4M):
pbcast.GMS(print_local_addr=true;join_timeout=3000;view_bundling=true):
FRAG2(frag_size=60K)"
propertySeparator="::"/>

<defaultCache maxEntriesLocalHeap="10000" eternal="false" overflowToDisk="true"
timeToIdleSeconds="600" timeToLiveSeconds="600" diskPersistent="false">

<cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
replicateUpdates=true, replicateUpdatesViaCopy=true,
replicateRemovals=true, asynchronousReplicationIntervalMillis=200" />

<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory"
properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=50000000"/>
</defaultCache>

<cache name="org.hibernate.cache.StandardQueryCache" maxElementsInMemory="10000"
eternal="false" timeToIdleSeconds="600" timeToLiveSeconds="600" overflowToDisk="true">

<cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,replicateUpdates=true,
replicateUpdatesViaCopy=true,replicateRemovals=true,asynchronousReplicationIntervalMillis=200" />

<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory"
properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=50000000"/>
</cache>

<cache name="org.hibernate.cache.UpdateTimestampsCache" maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="600" timeToLiveSeconds="600" overflowToDisk="true">

<cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,
replicateUpdatesViaCopy=true,replicateRemovals=true,asynchronousReplicationIntervalMillis=200" />

<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory"
properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=50000000"/>
</cache>
</ehcache>


三、Hibernate applicationContext.xml配置

<context:component-scan base-package="com.clusterehcache" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.clusterehcache.centity</value>
</list>
</property>
</bean>
四、Entity配置
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class User {
……
}
 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: