1 |
4676
|
antonis.le
|
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
|
|
|
3 |
|
|
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
4 |
|
|
xsi:noNamespaceSchemaLocation="ehcache.xsd" >
|
5 |
|
|
<diskStore path="java.io.tmpdir"/>
|
6 |
|
|
|
7 |
|
|
<!--
|
8 |
|
|
Cache configuration
|
9 |
|
|
===================
|
10 |
|
|
|
11 |
|
|
The following attributes are required.
|
12 |
|
|
|
13 |
|
|
name:
|
14 |
|
|
Sets the name of the cache. This is used to identify the cache. It must be unique.
|
15 |
|
|
|
16 |
|
|
maxElementsInMemory:
|
17 |
|
|
Sets the maximum number of objects that will be created in memory
|
18 |
|
|
|
19 |
|
|
maxElementsOnDisk:
|
20 |
|
|
Sets the maximum number of objects that will be maintained in the DiskStore
|
21 |
|
|
The default value is zero, meaning unlimited.
|
22 |
|
|
|
23 |
|
|
eternal:
|
24 |
|
|
Sets whether elements are eternal. If eternal, timeouts are ignored and the
|
25 |
|
|
element is never expired.
|
26 |
|
|
|
27 |
|
|
overflowToDisk:
|
28 |
|
|
Sets whether elements can overflow to disk when the memory store
|
29 |
|
|
has reached the maxInMemory limit.
|
30 |
|
|
|
31 |
|
|
The following attributes and elements are optional.
|
32 |
|
|
|
33 |
|
|
timeToIdleSeconds:
|
34 |
|
|
Sets the time to idle for an element before it expires.
|
35 |
|
|
i.e. The maximum amount of time between accesses before an element expires
|
36 |
|
|
Is only used if the element is not eternal.
|
37 |
|
|
Optional attribute. A value of 0 means that an Element can idle for infinity.
|
38 |
|
|
The default value is 0.
|
39 |
|
|
|
40 |
|
|
timeToLiveSeconds:
|
41 |
|
|
Sets the time to live for an element before it expires.
|
42 |
|
|
i.e. The maximum time between creation time and when an element expires.
|
43 |
|
|
Is only used if the element is not eternal.
|
44 |
|
|
Optional attribute. A value of 0 means that and Element can live for infinity.
|
45 |
|
|
The default value is 0.
|
46 |
|
|
|
47 |
|
|
diskPersistent:
|
48 |
|
|
Whether the disk store persists between restarts of the Virtual Machine.
|
49 |
|
|
The default value is false.
|
50 |
|
|
|
51 |
|
|
diskExpiryThreadIntervalSeconds:
|
52 |
|
|
The number of seconds between runs of the disk expiry thread. The default value
|
53 |
|
|
is 120 seconds.
|
54 |
|
|
|
55 |
|
|
diskSpoolBufferSizeMB:
|
56 |
|
|
This is the size to allocate the DiskStore for a spool buffer. Writes are made
|
57 |
|
|
to this area and then asynchronously written to disk. The default size is 30MB.
|
58 |
|
|
Each spool buffer is used only by its cache. If you get OutOfMemory errors consider
|
59 |
|
|
lowering this value. To improve DiskStore performance consider increasing it. Trace level
|
60 |
|
|
logging in the DiskStore will show if put back ups are occurring.
|
61 |
|
|
|
62 |
|
|
memoryStoreEvictionPolicy:
|
63 |
|
|
Policy would be enforced upon reaching the maxElementsInMemory limit. Default
|
64 |
|
|
policy is Least Recently Used (specified as LRU). Other policies available -
|
65 |
|
|
First In First Out (specified as FIFO) and Less Frequently Used
|
66 |
|
|
(specified as LFU)
|
67 |
|
|
|
68 |
|
|
Cache elements can also contain sub elements which take the same format of a factory class
|
69 |
|
|
and properties. Defined sub-elements are:
|
70 |
|
|
|
71 |
|
|
* cacheEventListenerFactory - Enables registration of listeners for cache events, such as
|
72 |
|
|
put, remove, update, and expire.
|
73 |
|
|
|
74 |
|
|
* bootstrapCacheLoaderFactory - Specifies a BootstrapCacheLoader, which is called by a
|
75 |
|
|
cache on initialisation to prepopulate itself.
|
76 |
|
|
|
77 |
|
|
* cacheExtensionFactory - Specifies a CacheExtension, a generic mechansim to tie a class
|
78 |
|
|
which holds a reference to a cache to the cache lifecycle.
|
79 |
|
|
|
80 |
|
|
* cacheExceptionHandlerFactory - Specifies a CacheExceptionHandler, which is called when
|
81 |
|
|
cache exceptions occur.
|
82 |
|
|
|
83 |
|
|
* cacheLoaderFactory - Specifies a CacheLoader, which can be used both asynchronously and
|
84 |
|
|
synchronously to load objects into a cache. More than one cacheLoaderFactory element
|
85 |
|
|
can be added, in which case the loaders form a chain which are executed in order. If a
|
86 |
|
|
loader returns null, the next in chain is called.
|
87 |
|
|
|
88 |
|
|
RMI Cache Replication
|
89 |
|
|
+++++++++++++++++++++
|
90 |
|
|
|
91 |
|
|
Each cache that will be distributed needs to set a cache event listener which replicates
|
92 |
|
|
messages to the other CacheManager peers. For the built-in RMI implementation this is done
|
93 |
|
|
by adding a cacheEventListenerFactory element of type RMICacheReplicatorFactory to each
|
94 |
|
|
distributed cache's configuration as per the following example:
|
95 |
|
|
|
96 |
|
|
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
|
97 |
|
|
properties="replicateAsynchronously=true,
|
98 |
|
|
replicatePuts=true,
|
99 |
|
|
replicatePutsViaCopy=false,
|
100 |
|
|
replicateUpdates=true,
|
101 |
|
|
replicateUpdatesViaCopy=true,
|
102 |
|
|
replicateRemovals=true
|
103 |
|
|
asynchronousReplicationIntervalMillis=<number of milliseconds"
|
104 |
|
|
propertySeparator="," />
|
105 |
|
|
|
106 |
|
|
The RMICacheReplicatorFactory recognises the following properties:
|
107 |
|
|
|
108 |
|
|
* replicatePuts=true|false - whether new elements placed in a cache are
|
109 |
|
|
replicated to others. Defaults to true.
|
110 |
|
|
|
111 |
|
|
* replicatePutsViaCopy=true|false - whether the new elements are
|
112 |
|
|
copied to other caches (true), or whether a remove message is sent. Defaults to true.
|
113 |
|
|
|
114 |
|
|
* replicateUpdates=true|false - whether new elements which override an
|
115 |
|
|
element already existing with the same key are replicated. Defaults to true.
|
116 |
|
|
|
117 |
|
|
* replicateRemovals=true - whether element removals are replicated. Defaults to true.
|
118 |
|
|
|
119 |
|
|
* replicateAsynchronously=true | false - whether replications are
|
120 |
|
|
asynchronous (true) or synchronous (false). Defaults to true.
|
121 |
|
|
|
122 |
|
|
* replicateUpdatesViaCopy=true | false - whether the new elements are
|
123 |
|
|
copied to other caches (true), or whether a remove message is sent. Defaults to true.
|
124 |
|
|
|
125 |
|
|
* asynchronousReplicationIntervalMillis=<number of milliseconds> - The asynchronous
|
126 |
|
|
replicator runs at a set interval of milliseconds. The default is 1000. The minimum
|
127 |
|
|
is 10. This property is only applicable if replicateAsynchronously=true
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
JGroups Replication
|
131 |
|
|
+++++++++++++++++++
|
132 |
|
|
|
133 |
|
|
For the Jgroups replication this is done with:
|
134 |
|
|
<cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
|
135 |
|
|
properties="replicateAsynchronously=true, replicatePuts=true,
|
136 |
|
|
replicateUpdates=true, replicateUpdatesViaCopy=false,
|
137 |
|
|
replicateRemovals=true,asynchronousReplicationIntervalMillis=1000"/>
|
138 |
|
|
This listener supports the same properties as the RMICacheReplicationFactory.
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
JMS Replication
|
142 |
|
|
+++++++++++++++
|
143 |
|
|
|
144 |
|
|
For JMS-based replication this is done with:
|
145 |
|
|
<cacheEventListenerFactory
|
146 |
|
|
class="net.sf.ehcache.distribution.jms.JMSCacheReplicatorFactory"
|
147 |
|
|
properties="replicateAsynchronously=true,
|
148 |
|
|
replicatePuts=true,
|
149 |
|
|
replicateUpdates=true,
|
150 |
|
|
replicateUpdatesViaCopy=true,
|
151 |
|
|
replicateRemovals=true,
|
152 |
|
|
asynchronousReplicationIntervalMillis=1000"
|
153 |
|
|
propertySeparator=","/>
|
154 |
|
|
|
155 |
|
|
This listener supports the same properties as the RMICacheReplicationFactory.
|
156 |
|
|
|
157 |
|
|
Cluster Bootstrapping
|
158 |
|
|
+++++++++++++++++++++
|
159 |
|
|
(RMI clusters only)
|
160 |
|
|
|
161 |
|
|
The RMIBootstrapCacheLoader bootstraps caches in clusters where RMICacheReplicators are
|
162 |
|
|
used. It is configured as per the following example:
|
163 |
|
|
|
164 |
|
|
<bootstrapCacheLoaderFactory
|
165 |
|
|
class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
|
166 |
|
|
properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"
|
167 |
|
|
propertySeparator="," />
|
168 |
|
|
|
169 |
|
|
The RMIBootstrapCacheLoaderFactory recognises the following optional properties:
|
170 |
|
|
|
171 |
|
|
* bootstrapAsynchronously=true|false - whether the bootstrap happens in the background
|
172 |
|
|
after the cache has started. If false, bootstrapping must complete before the cache is
|
173 |
|
|
made available. The default value is true.
|
174 |
|
|
|
175 |
|
|
* maximumChunkSizeBytes=<integer> - Caches can potentially be very large, larger than the
|
176 |
|
|
memory limits of the VM. This property allows the bootstraper to fetched elements in
|
177 |
|
|
chunks. The default chunk size is 5000000 (5MB).
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
Cache Exception Handling
|
181 |
|
|
|
182 |
|
|
By default, most cache operations will propagate a runtime CacheException on failure. An
|
183 |
|
|
interceptor, using a dynamic proxy, may be configured so that a CacheExceptionHandler can
|
184 |
|
|
be configured to intercept Exceptions. Errors are not intercepted.
|
185 |
|
|
|
186 |
|
|
It is configured as per the following example:
|
187 |
|
|
|
188 |
|
|
<cacheExceptionHandlerFactory class="com.example.ExampleExceptionHandlerFactory"
|
189 |
|
|
properties="logLevel=FINE"/>
|
190 |
|
|
|
191 |
|
|
Caches with ExceptionHandling configured are not of type Cache, but are of type Ehcache only,
|
192 |
|
|
and are not available using CacheManager.getCache(), but using CacheManager.getEhcache().
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
Cache Loader
|
196 |
|
|
|
197 |
|
|
A default CacheLoader may be set which loads objects into the cache through asynchronous and
|
198 |
|
|
synchronous methods on Cache. This is different to the bootstrap cache loader, which is used
|
199 |
|
|
only in distributed caching.
|
200 |
|
|
|
201 |
|
|
It is configured as per the following example:
|
202 |
|
|
|
203 |
|
|
<cacheLoaderFactory class="com.example.ExampleCacheLoaderFactory"
|
204 |
|
|
properties="type=int,startCounter=10"/>
|
205 |
|
|
|
206 |
|
|
Cache Extension
|
207 |
|
|
|
208 |
|
|
CacheExtensions are a general purpose mechanism to allow generic extensions to a Cache.
|
209 |
|
|
CacheExtensions are tied into the Cache lifecycle.
|
210 |
|
|
|
211 |
|
|
CacheExtensions are created using the CacheExtensionFactory which has a
|
212 |
|
|
<code>createCacheCacheExtension()</code> method which takes as a parameter a
|
213 |
|
|
Cache and properties. It can thus call back into any public method on Cache, including, of
|
214 |
|
|
course, the load methods.
|
215 |
|
|
|
216 |
|
|
Extensions are added as per the following example:
|
217 |
|
|
|
218 |
|
|
<cacheExtensionFactory class="com.example.FileWatchingCacheRefresherExtensionFactory"
|
219 |
|
|
properties="refreshIntervalMillis=18000, loaderTimeout=3000,
|
220 |
|
|
flushPeriod=whatever, someOtherProperty=someValue ..."/>
|
221 |
|
|
|
222 |
|
|
-->
|
223 |
|
|
|
224 |
|
|
<!--
|
225 |
|
|
Mandatory Default Cache configuration. These settings will be applied to caches
|
226 |
|
|
created programmtically using CacheManager.add(String cacheName).
|
227 |
|
|
|
228 |
|
|
The defaultCache has an implicit name "default" which is a reserved cache name.
|
229 |
|
|
-->
|
230 |
|
|
<defaultCache
|
231 |
5053
|
antonis.le
|
maxElementsInMemory="1000"
|
232 |
11979
|
katerina.i
|
eternal="false"
|
233 |
4676
|
antonis.le
|
timeToIdleSeconds="120"
|
234 |
|
|
timeToLiveSeconds="120"
|
235 |
5053
|
antonis.le
|
overflowToDisk="false"
|
236 |
4676
|
antonis.le
|
diskSpoolBufferSizeMB="30"
|
237 |
|
|
maxElementsOnDisk="10000000"
|
238 |
|
|
diskPersistent="false"
|
239 |
|
|
diskExpiryThreadIntervalSeconds="120"
|
240 |
|
|
memoryStoreEvictionPolicy="LRU"
|
241 |
|
|
/>
|
242 |
|
|
</ehcache>
|