|
1、首先设置EhCache,建立配置文件ehcache.xml,默认的位置在class-path,可以放到你的src目录下: <?xml version="1.0" encoding="UTF-8"?>
; _/ J7 \$ u! F9 q, q' k) E<ehcache>- {. q: L( j. Q6 g/ J' j! ?6 y+ E) V
<diskStore path="java.io.tmpdir"/>- F# O0 } e) ?
<defaultCache" h+ H$ g, P' P
maxElementsInMemory="10000" <!-- 缓存最大数目 -->( { K' K j/ J6 m% f9 n
eternal="false" <!-- 缓存是否持久 --> overflowToDisk="true" <!-- 是否保存到磁盘,当系统当机时--> timeToIdleSeconds="300" <!-- 当缓存闲置n秒后销毁 -->
5 X& S) F1 K- }. _, S# G9 U timeToLiveSeconds="180" <!-- 当缓存存活n秒后销毁-->
. [6 |: g6 b6 d3 Q+ ] diskPersistent="false"
! R; h, C( s: Z( e diskExpiryThreadIntervalSeconds= "120"/>
9 q$ ]" n A$ V% U! G6 ]. ^</ehcache> 2、在hibernate配置文件中设置: <!-- 设置Hibernate的缓存接口类,这个类在Hibernate包中 -->
, Y- Y* o: {& X) W. B( v X<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>3 R2 x' v D* p& b
<!-- 是否使用查询缓存 --> <property name="hibernate.cache.use_query_cache">true</property>
$ E: D6 C! L& {- L! J* j 如果使用spring调用Hibernate的sessionFactory的话,这样设置: v. ]' Y& |. d; B8 L0 G1 w/ y
<!--HibernateSession工厂管理 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">& g! O) K b2 O* W }
<property name="dataSource">/ L: p0 u- Y: q3 \- K
<ref bean="datasource" />" U: b- }! |) O' w; G) o
</property>4 v1 A5 f( z* z3 |3 N
<property name="hibernateProperties">. r* {& R1 Y" r. K
<props>/ I' S" f7 D; n" z& h
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>& V# h8 d" V4 B1 h
<prop key="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
5 r2 ~7 n! H& r/ S <prop key="hibernate.show_sql">true</prop>% l! `- m3 G% R9 R
<prop key="hibernate.cache.use_query_cache">true</prop>
t. |1 E) e: q, Q( j4 e) B4 L, v <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
8 z: K: m0 `! @" ^% B% p% ]% O u </props>) Y. [7 ^+ R4 H5 _
</property>
& `, d2 N7 T8 k5 e0 s <property name="mappingDirectoryLocations"># }* U; ]- j1 T
<list>
: n& y5 K: d$ _/ I. C <value>/WEB-INF/classes/cn/rmic/manager/hibernate/</value>& c+ p! N8 _ N
</list>
% D; M0 m- p3 e4 y1 c; a* B </property>
$ F+ B( H1 S! {8 f( N</bean> 说明一下:如果不设置“查询缓存”,那么hibernate只会缓存使用load()方法获得的单个持久化对象,如果想缓存使用findall()、list()、Iterator()、createCriteria()、createQuery()等方法获得的数据结果集的话,就需要设置hibernate.cache.use_query_cache true 才行 3、在Hbm文件中添加<cache usage="read-only"/> " S0 Q7 x4 p9 k4 R5 _8 O) U. j3 U
4、如果需要“查询缓存”,还需要在使用Query或Criteria()时设置其setCacheable(true);属性 5、实践出真知,给一段测试程序,如果成功的话第二次查询时不会读取数据库 package cn.rmic.hibernatesample; import java.util.List; import org.hibernate.CacheMode;
; A8 |" m) J5 n6 {; ^& R* iimport org.hibernate.Criteria;# m% f' j: y2 M! B$ G% x
import org.hibernate.Query;9 Y1 a6 y. b- ~! q
import org.hibernate.Session; import cn.rmic.hibernatesample.hibernate.HibernateSessionFactory;
3 @- G' w2 B4 ~+ `9 Cimport cn.rmic.manager.po.Resources; public class testCacheSelectList ...{ public static void main(String[] args) ...{. u, K5 i( A) O+ t/ v/ k3 M
Session s=HibernateSessionFactory.getSession();
5 b# {. j/ l6 C Criteria c=s.createCriteria(Resources.class);
! B9 a. V' b6 G+ ^ c.setCacheable(true);
( U+ b/ y! R g9 _& X. W3 y: { List l=c.list(); Resources resources=(Resources)l.get(0);
7 x$ d0 }( R3 K System.out.println("-1-"+resources.getName());
1 @! B: l9 M/ C: F" o1 D0 O7 U0 B HibernateSessionFactory.closeSession();
+ _: m& a8 W% k try ...{$ q, n: D# x4 q& ^
Thread.sleep(5000);
: E+ D- U3 x- w1 N } catch (InterruptedException e) ...{& H8 {" Q. A0 N( A4 U
// TODO Auto-generated catch block' U) x! Y& V N9 Z& }: k
e.printStackTrace();7 a2 H2 H* t1 ?7 S
}/ S/ y v0 Q, Z
s=HibernateSessionFactory.getSession();& p( Y% Y( G1 X" O" s8 t) \
c=s.createCriteria(Resources.class);; _8 H$ P) D- V
c.setCacheable(true);7 y( s, {; N/ `; T. ^
l=c.list();0 r3 b* ?1 ]* M' z
resources=(Resources)l.get(0);
! ?& l4 }6 S6 t8 n! B System.out.println("-2-"+resources.getName());% J( C% C! Z! A
HibernateSessionFactory.closeSession();
- E6 I8 O U( X' D }
) [- V# X5 \' m6 E( J" p8 a- w}
7 o( Z W$ t+ E6 F1. 在Hibernate配置文件中设置:
$ u; `) F& O! F( U <!-- Hibernate SessionFactory -->
. u2 t! X" @3 p6 T b <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
3 `4 k* y8 _& o# t" ^# D6 o <property name="dataSource" ref="dataSource"/>
1 y7 f2 y8 X8 u- r <property name="mappingResources">/ Q" J" ?- a( h% z; q% w+ P/ _+ J5 {3 C
<list>) d$ A% |0 c) f* v' ^# C! x
<value>com/ouou/model/Videos.hbm.xml</value>
" h: P- n2 u) o x6 c7 c3 D0 o! n </list>( i; ~& ]4 B g
</property>
9 [4 f! f5 \: {% b4 m0 H <property name="hibernateProperties">
z. a9 g" Z! s4 R* J0 w <props>: ~# U. `6 N+ X2 o! J
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>6 S, s% C, q. b
<prop key="hibernate.current_session_context_class">thread</prop>
1 f$ o4 c! v1 r/ _% P2 p$ a4 { <prop key="hibernate.cglib.use_reflection_optimizer">false</prop>( O# w7 d( k- F& ?8 W: b5 Q( g8 [
<prop key="hibernate.query.substitutions">true 'Y', false 'N'</prop>
& w$ w$ H- V1 g; L' \ <!--add ehcache-->, b: \+ g8 @; \- F. Q$ V
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
+ y4 `: l" o* \& x <prop key="hibernate.cache.use_query_cache">false</prop><!-- 是否使用查询缓存 -->
' i5 f2 r9 ?/ ^0 L2 @1 } <!--! w. }9 D% h! @; _: @
<prop key="hibernate.cache.provider_configuration_file_resource_path">/ehcache.xml</prop>7 G' x. w T7 D
<prop key="hibernate.show_sql">true</prop>! o* B2 {. K2 J, i. q; h
-->5 w) J; c+ q7 F7 a
<!--<prop key="hibernate.transaction.auto_close_session">true</prop>-->4 W9 j/ K& O+ b8 V0 W
<prop key="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>* J) y5 R4 _ \) ^2 f
<!-- Create/update the database tables automatically when the JVM starts up, I1 w* Z& w7 ~
<prop key="hibernate.hbm2ddl.auto">update</prop> -->
5 V: O/ b0 m1 x( W' z. @5 P <!-- Turn batching off for better error messages under PostgreSQL -->
2 c7 F! h" M* l+ { <prop key="hibernate.jdbc.batch_size">25</prop>+ G4 H6 Y# l) T! A, ]3 ~; ~( Z
<!--. f7 P; F( z- Y
<prop key="hibernate.connection.pool_size">10</prop>
: ^5 v. U3 A8 N# a -->
, I6 P( Q3 ?' j: B( [ </props>
* m9 [( D% W$ n6 F N6 A' _ </property>
% c3 q- o! S, T </bean> 如果不设置“查询缓存”,那么hibernate只会缓存使用load()方法获得的单个持久化对象,如果想缓存使用findall()、 list()、Iterator()、createCriteria()、createQuery()等方法获得的数据结果集的话,就需要设置hibernate.cache.use_query_cache true 才行 2.首先设置EhCache,建立配置文件ehcache.xml,默认的位置在class-path,可以放到你的src目录下:
) H; ]1 c- G* t6 T) ] <ehcache>
<!-- Sets the path to the directory where cache .data files are created. If the path is a Java System Property it is replaced by
7 S- C3 k* W! U; h2 ? its value in the running VM.
# h2 p" X4 e2 p6 p7 `3 u The following properties are translated:
/ G1 z& ~1 T% ^. n: q user.home - User's home directory
( m- g. {. {+ ?+ V user.dir - User's current working directory
* O) d) a% ^8 r* J java.io.tmpdir - Default temp file path -->
5 c3 C" u& [9 X r( Y <!--<diskStore path="java.io.tmpdir"/>-->
, A: i6 _: V8 o <diskStore path="/data/ehcache"/> <!--Default Cache configuration. These will applied to caches programmatically created through, C( s4 o: p7 k/ Q* A6 T: c# S
the CacheManager. The following attributes are required: maxElementsInMemory - Sets the maximum number of objects that will be created in memory
H9 a; S2 y7 Z* V* X9 q0 v2 Z6 l- B eternal - Sets whether elements are eternal. If eternal, timeouts are5 k/ m( Y; t, `% a$ w
ignored and the element is never expired.3 U+ E' v) \7 f
overflowToDisk - Sets whether elements can overflow to disk when the in-memory cache7 I* P& C" F9 ]0 E }
has reached the maxInMemory limit. The following attributes are optional:
6 P/ O4 I6 a0 w' j0 j! L timeToIdleSeconds - Sets the time to idle for an element before it expires.
; v1 D% y( c+ a i.e. The maximum amount of time between accesses before an
B2 R4 h6 ]9 {+ S. ?0 ?0 \, }: p element expires Is only used if the element is not eternal.4 W' s O+ X! A& ~ q3 B
Optional attribute. A value of 0 means that an Element can idle* g' D- X2 t$ i3 m3 u0 o8 Z
for infinity.The default value is 0.) `. n" A- O7 w% N3 `
timeToLiveSeconds - Sets the time to live for an element before it expires.+ }9 m$ N8 i1 Z3 [8 h6 W) E5 M9 o% i: S
i.e. The maximum time between creation time and when an element/ j; g. o3 `- I' d; R
expires. Is only used if the element is not eternal.- Z3 u5 p! o' I* L f- b
Optional attribute. A value of 0 means that and Element can live* ?4 o, K( c5 ^3 U, d
for infinity.6 Z0 F1 @. _: F* s: w
The default value is 0.
* Y% N9 o }$ I7 V diskPersistent - Whether the disk store persists between restarts of the Virtual$ ^8 ?- D0 \ a& S+ h
Machine.
% U/ n/ z3 M- ^, A6 k9 c; b$ T( D The default value is false.
* f S1 N1 ~8 e J" t' `5 Q diskExpiryThreadIntervalSeconds - The number of seconds between runs of the disk expiry thread." U) T8 G" l I( X7 {; C
The default value is 120 seconds.
2 c) n% F; C& S: z" s8 P/ p6 e7 d --> <defaultCache
% q, e, Q: f! K( I maxElementsInMemory="10000"
8 o6 O& `7 ^5 l: G; `) { eternal="false"' A: c3 Q- J/ G; {& w% |. ?7 b+ w
overflowToDisk="true"
2 F% t: n+ W/ `- P, R( A' x timeToIdleSeconds="120"+ t# h7 [$ J3 w0 a+ U& g7 b5 ^
timeToLiveSeconds="120"
5 C/ E7 L5 L. Q; c diskPersistent="false"& T8 U4 e3 T) ?5 }, R* B
diskExpiryThreadIntervalSeconds="120"/>" J4 p+ a0 |1 ~' X( W) g6 A. ?
<cache name="org.hibernate.cache.UpdateTimestampsCache" maxElementsInMemory="5000"
, P- V+ t$ U$ N* e6 B eternal="true" overflowToDisk="true"/>6 R* i' p# y2 J' C
<cache name="org.hibernate.cache.StandardQueryCache" maxElementsInMemory="5" eternal="false"7 ^+ {! H2 ^+ ~& h8 A' @0 I
timeToLiveSeconds="120" overflowToDisk="true"/>
6 P8 C( s9 p8 \2 [+ F <cache name="userCache" maxElementsInMemory="100000" eternal="false" timeToIdleSeconds=
' [) w- \, X# a "600" timeToLiveSeconds="600" overflowToDisk="false" diskPersistent="false"/>
' g ?/ Y4 h7 F, A" P* P; z <cache name="com.ouou.webapp.util.OuouMethodIntecepter" maxElementsInMemory="100000"
# g6 B1 b1 L3 C8 S eternal="false" timeToIdleSeconds="600" timeToLiveSeconds="600" overflowToDisk="false"8 J9 m, m" {& H0 P& B1 y1 G+ b3 D
diskPersistent="false"/>
: f0 s. b3 r9 [( c <cache name="bbcode" maxElementsInMemory="100000" eternal="false" timeToIdleSeconds="600"" p4 s' h5 M `* c+ {1 B4 D
timeToLiveSeconds="600"
* v% [ }/ b+ [ G overflowToDisk="false" diskPersistent="false"/>6 o5 H2 W( `7 Z- q
<cache name="com.ouou.model.Videos" maxElementsInMemory="10000" eternal="false"" [* v# ]. a2 p' j8 H0 q! ?2 y+ I
overflowToDisk="false" timeToIdleSeconds="120" timeToLiveSeconds="120" diskPersistent="false"/>
. W0 j5 ^) e5 Y. H' Y6 ` <cache name="com.ouou.model.Tags" maxElementsInMemory="10000" eternal="false"; a7 I4 G! p5 ^5 J* u' Q# L( L
overflowToDisk="false" timeToIdleSeconds="120" timeToLiveSeconds="120" diskPersistent="false"/>* z6 e) X7 f; q
</ehcache> 以com.ouou.model.Videos为例子
3 C1 r% b; W0 C在Videos.hbm.xml中配置:
8 d1 ?+ U. c! u* }+ P) h<class name="Videos" table="TEST" lazy="false">, v: }4 K0 f# y* r" ^ L7 M
<cache usage="read-write" region="ehcache.xml中的name的属性值"/>注意:这一句需要紧跟在class标签下面,其他位置无效。) S q: v) Q7 z+ j5 p. x. g
hbm文件查找cache方法名的策略:如果不指定hbm文件中的region="ehcache.xml中的name的属性值",则使用name名为com.ouou.model.Videos的cache,
& G1 D1 v% F# W" C如果不存在与类名匹配的cache名称,则用defaultCache。
+ r- ]' z3 `" H4 L# P如果Videos包含set集合,则需要另行指定其cache$ A6 b0 c8 H1 b1 B/ e
例如Videos包含Tags集合,则需要
2 B$ K# n; s* s$ K& }; i添加如下配置到ehcache.xml中4 L3 ~8 X; d9 g- r2 k
<cache name="com.ouou.model.Tags"
( j" X/ S4 C: k& @: K8 b' Z, { maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120"6 f' `0 \/ F* [6 m
timeToLiveSeconds="120" overflowToDisk="false" />$ `" [- C0 }* ~' [( ]/ Q
另,针对查询缓存的配置如下:
0 L. q+ B/ m4 T& @/ r2 Y: X<cache name="org.hibernate.cache.UpdateTimestampsCache"
0 D$ K$ ]' @. ?7 G! r maxElementsInMemory="5000"
0 Z( o4 i/ K& V1 n. x; L' l# i eternal="true"7 T' ~$ i0 I2 v9 C. H
overflowToDisk="true"/>
+ N% T! M. o4 S0 y<cache name="org.hibernate.cache.StandardQueryCache"
3 t1 j/ R4 L0 n" @! l! O maxElementsInMemory="10000"1 x7 L, e, c3 O
eternal="false"
c! Q1 {2 q6 `) j$ m timeToLiveSeconds="120". `. J3 ~/ C" x. B: \1 W2 F
overflowToDisk="true"/> 3、 选择缓存策略依据: <cache usage="transactional|read-write|nonstrict-read-write|read-only" (1)/>: ], f% E% ]% U6 {! v
ehcache不支持transactional,其他三种可以支持。
0 |$ ~0 e5 R) y9 qread-only:无需修改, 那么就可以对其进行只读 缓存,注意,在此策略下,如果直接修改数据库,即使能够看到前台显示效果,- P9 e0 {1 {$ g& m3 G$ F- k
但是将对象修改至cache中会报error,cache不会发生作用。另:删除记录会报错,因为不能在read-only模式的对象从cache中删除。
7 c0 V* t5 _3 `, vread-write:需要更新数据,那么使用读/写缓存 比较合适,前提:数据库不可以为serializable transaction isolation level( D2 h- C! f6 m/ o' h
(序列化事务隔离级别)
2 Z! p# M/ C# h# wnonstrict-read-write:只偶尔需要更新数据(也就是说,两个事务同时更新同一记录的情况很不常见),也不需要十分严格的事务隔离,- j6 v5 |9 z2 f9 n! Z( k
那么比较适合使用非严格读/写缓存策略。 4、 调试时候使用log4j的log4j.logger.org.hibernate.cache=debug,更方便看到ehcache的操作过程,主要用于调试过程,实际应用发布时候,请注释掉,以免影响性能。 5、 使用ehcache,打印sql语句是正常的,因为query cache设置为true将会创建两个缓存区域:一个用于保存查询结果集 (
: B& z# [; ?1 G9 ?% norg.hibernate.cache.StandardQueryCache);另一个则用于保存最近查询的一系列表的时间戳(org.hibernate.cache.UpdateTimestampsCache)。
/ F$ @$ O6 O) B4 `5 u! b# V5 L请注意:在查询缓存中,它并不缓存结果集中所包含的实体的确切状态;它只缓存这些实体的标识符属性的值、以及各值类型的结果。8 w3 M, N* W$ j: s9 Z. r7 g5 R m
需要将打印sql语句与最近的cache内容相比较,将不同之处修改到cache中,所以查询缓存通常会和二级缓存一起使用。
2 s. N% s% [9 Z( ~0 lEhcache的配置说明 ( \* X/ {7 U3 F2 v2 b
<ehcache>/ Q7 s2 l" _+ }# H( n5 E2 a
<!--. l: v- J7 Z# g$ ^2 d5 [
磁盘存储配置:: Z5 c4 w) P( I+ B$ x9 O
用来指定缓存在磁盘上的存储位置。可以使用JavaVM环境变量(user.home, user.dir, java.io.tmpdir)2 R6 S, s9 V2 q7 } B$ H( j
-->
5 C% _& r6 z! [6 h5 j<diskStore path = "/var/apps/cache/" />
- b. n% ^. h& B1 `! w" H<!--7 P' b. K0 v2 j6 Z" R# f N# ^
指定CacheManagerEventListenerFactory,这个对象在缓存添加的时候会得到相应的通知
6 a; b% S6 p, h5 V( M$ n* O$ cCacheManagerEventListenerFactory的属性5 s. R2 e/ W* ~' f9 }
*class - CacheManagerEventListenerFactory的一个实现类
+ {. J! J+ y' f) {*properties - CacheManagerEventListenerFactory的属性值,以逗号(,)分割多个属性" B+ r* G. q `8 ]
如果没有实现类被指定,则系统不创建CacheManager的监听器,没有默认值3 C6 H" `7 z2 w, Q9 v1 o d6 m
-->
s, y1 N6 Q! Y7 J+ ^<cacheManagerEventListenerFactory class="" properties="" />
0 f/ o3 r5 A& \7 J X+ K, y. p% @. V<!--
# r) _2 z7 J: I+ j0 H在进行分布式缓存的应用时候需要指定CacheManagerPeerProviderFactory,! c3 N* P5 V4 x, h+ b
用来生成CacheManagerPeerProvider的实例,以便和集群中的其他CacheManager通信。% e, d* O9 R2 a& j% w
*class -CacheManagerPeerProviderFactory的一个实现类
8 D, c6 Z" r2 u& y7 m*properties - CacheManagerPeerProviderFactory的属性值,以逗号(,)分割多个属性7 Z! J2 b, B6 X
Ehcache内建了2种基于RMI分布系统的通信策略:, G! t5 A$ {# ?# S: @) v( k; h
*automatic - 使用多播组。在一个节点加入或者推出集群的时候自动感应4 d ]; n% l8 a6 H, j
*manual - 硬编码方式 目前的awf中不考虑分布缓存
; X( _5 R [/ O% L6 s-->' z9 J/ i' k/ x
<cacheManagerPeerListenerFactory class="" properties="" />
9 a1 C6 [/ r, Z% _6 e! h" d- [4 l<!--
' p2 }7 r+ Q! g/ m. `缓存配置。
+ W) Q j6 |/ c" {7 O以下属性是必须的:
2 q& c: I* E; N/ l5 m. v# pname - cache的标识符,在一个CacheManager中必须唯一
, h+ \+ d( {! l- w9 C" q: C* ~maxElementsInMemory - 在内存中缓存的element的最大数目( \5 _: p+ q6 `5 A6 f4 B
maxElementsOnDisk - 在磁盘上缓存的element的最大数目0 d' }! l; `: g' j! P! S2 M
eternal - 设定缓存的elements是否有有效期。如果为true,timeouts属性被忽略
' B, |8 ]5 |+ zoverflowToDisk - 设定当内存缓存溢出的时候是否将过期的element缓存到磁盘上
, i8 E5 f( t& S4 `! V以下属性是可选的:9 |! ] `, C0 P( }6 f* J
timeToIdleSeconds - 缓存element在过期前的空闲时间。默认为0,表示可空闲无限时间.- U4 {2 @+ w* m
(如果指定了这个时间,是否在被hit的前超过了这个时间就会被remove?在内存缓存数目超限之前不会被remove)) ?# U I; p5 Z) r, v& N
timeToLiveSeconds - 缓存element的有效生命期。这个类似于timeouts,默认为0,不过期( L/ v F& a3 ]5 c! s; U- J
(是否通常情况下应该大于等于timeToIdleSeconds,小于会如何?idle时间也会减小和这个数值一样)& x/ u& F X8 G8 S/ F
diskPersistent - 在VM重启的时候是否持久化磁盘缓存,默认是false。
! Q" S$ w, d9 ]- f5 a (测试一下true的情况?重载vm的时候会从磁盘进行序列化到对象)
3 B7 w0 {: _/ ydiskExpiryThreadIntervalSeconds - 磁盘缓存的清理线程运行间隔,默认是120秒.0 L" ]6 P+ M T V& X
(测试一下0的时候会如何)
) r2 S7 H5 O0 y! {) H2 U/ Z. rmemoryStoreEvictionPolicy - 当内存缓存达到最大,有新的element加入的时候,; V9 J s9 B' S# `& c( ~7 N
移除缓存中element的策略。默认是LRU,可选的有LFU和FIFO 可对缓存中的element配置诸如监听器和加载器。Ehcahe内建了一些
4 M) N6 w! j- x4 y*cacheEventListenerFactory - 监听缓存中element的put, remove, update和expire事件* I$ c! ?7 d! V3 R
*bootstrapCacheLoaderFactory - 启动时加载缓存的element p/ R; ~5 C" |3 o- ]' L
每个用来做分布式缓存都必须设定element的事件监听器,用来在各个CacheManager节点复制消息。
+ j7 u$ ~0 G2 z% A: MEhcache内建了基于RMI的实现 - RMICacheReplicatorFactory
: j/ Z* m4 T9 V( @/ ~, F% S8 W <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"# e* {( b$ b" u6 k, U$ T1 \
properties="replicateAsynchronouly=true," U! P, _& K8 n7 n. j$ k! @1 o
replicatePuts=true, r W) ~# {/ p. k
replicateUpdates=true,; ~: t" l6 y$ M+ p6 o
replicateUpdateViaCopy=true,+ @& |7 Y2 f: }. _$ A7 T
replicateRemovals=true" /> -->7 k) g# ^8 c4 H- L- Q) }) T& B( e7 T
<cache .... />8 Q1 a U; A& M, ]7 }
<!--
* m2 P, b( l% S2 Y2 w, ]; x默认的Cache配置。用来实现CacheManager.add(String cacheName)创建的缓存
; E) W5 _7 O/ y& c-->
~, x f4 x& q. F- T<defaultCache maxElementsInMemory="10000" eternal="false"2 ^+ T4 ^+ Y: M7 M
timeToIdleSeconds="120" timeToLiveSeconds="120"$ O+ I4 F8 V: D8 r
overflowToDisk="true" maxElementsOnDisk="1000000"8 e# u+ w9 ?1 b1 r _, F3 O$ B
diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
5 |6 J7 a9 @2 p+ v8 S7 i memoryStoreEvictionPolicy="LRU"4 d6 G! [9 o7 `
/> </ehcache> ! N Z+ ]0 o7 |3 s7 i$ L
|