| 1 |
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd"> |
| 2 |
|
| 3 |
<!-- |
| 4 |
The ehcache-failsafe.xml is a default configuration for ehcache, if an ehcache.xml is not configured. |
| 5 |
|
| 6 |
The diskStore element is optional. It must be configured if you have overflowToDisk or diskPersistent enabled |
| 7 |
for any cache. If it is not configured, a warning will be issues and java.io.tmpdir will be used. |
| 8 |
|
| 9 |
diskStore has only one attribute - "path". It is the path to the directory where .data and .index files will be created. |
| 10 |
|
| 11 |
If the path is a Java System Property it is replaced by its value in the |
| 12 |
running VM. |
| 13 |
|
| 14 |
The following properties are translated: |
| 15 |
* user.home - User's home directory |
| 16 |
* user.dir - User's current working directory |
| 17 |
* java.io.tmpdir - Default temp file path |
| 18 |
* ehcache.disk.store.dir - A system property you would normally specify on the command line |
| 19 |
e.g. java -Dehcache.disk.store.dir=/u01/myapp/diskdir ... |
| 20 |
|
| 21 |
Subdirectories can be specified below the property e.g. java.io.tmpdir/one |
| 22 |
|
| 23 |
--> |
| 24 |
<diskStore path="java.io.tmpdir"/> |
| 25 |
|
| 26 |
<!-- |
| 27 |
Specifies a CacheManagerEventListenerFactory, be used to create a CacheManagerPeerProvider, |
| 28 |
which is notified when Caches are added or removed from the CacheManager. |
| 29 |
|
| 30 |
The attributes of CacheManagerEventListenerFactory are: |
| 31 |
* class - a fully qualified factory class name |
| 32 |
* properties - comma separated properties having meaning only to the factory. |
| 33 |
|
| 34 |
Sets the fully qualified class name to be registered as the CacheManager event listener. |
| 35 |
|
| 36 |
The events include: |
| 37 |
* adding a Cache |
| 38 |
* removing a Cache |
| 39 |
|
| 40 |
Callbacks to listener methods are synchronous and unsynchronized. It is the responsibility |
| 41 |
of the implementer to safely handle the potential performance and thread safety issues |
| 42 |
depending on what their listener is doing. |
| 43 |
|
| 44 |
If no class is specified, no listener is created. There is no default. |
| 45 |
|
| 46 |
<cacheManagerEventListenerFactory class="" properties=""/> |
| 47 |
--> |
| 48 |
|
| 49 |
<!-- |
| 50 |
(Enable for distributed operation) |
| 51 |
|
| 52 |
Specifies a CacheManagerPeerProviderFactory which will be used to create a |
| 53 |
CacheManagerPeerProvider, which discovers other CacheManagers in the cluster. |
| 54 |
|
| 55 |
The attributes of cacheManagerPeerProviderFactory are: |
| 56 |
* class - a fully qualified factory class name |
| 57 |
* properties - comma separated properties having meaning only to the factory. |
| 58 |
|
| 59 |
Ehcache comes with a built-in RMI-based distribution system with two means of discovery of |
| 60 |
CacheManager peers participating in the cluster: |
| 61 |
* automatic, using a multicast group. This one automatically discovers peers and detects |
| 62 |
changes such as peers entering and leaving the group |
| 63 |
* manual, using manual rmiURL configuration. A hardcoded list of peers is provided at |
| 64 |
configuration time. |
| 65 |
|
| 66 |
Configuring Automatic Discovery: |
| 67 |
Automatic discovery is configured as per the following example: |
| 68 |
<cacheManagerPeerProviderFactory |
| 69 |
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" |
| 70 |
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, |
| 71 |
multicastGroupPort=4446, timeToLive=32"/> |
| 72 |
|
| 73 |
Valid properties are: |
| 74 |
* peerDiscovery (mandatory) - specify "automatic" |
| 75 |
* multicastGroupAddress (mandatory) - specify a valid multicast group address |
| 76 |
* multicastGroupPort (mandatory) - specify a dedicated port for the multicast heartbeat |
| 77 |
traffic |
| 78 |
* timeToLive - specify a value between 0 and 255 which determines how far the packets will propagate. |
| 79 |
By convention, the restrictions are: |
| 80 |
0 - the same host |
| 81 |
1 - the same subnet |
| 82 |
32 - the same site |
| 83 |
64 - the same region |
| 84 |
128 - the same continent |
| 85 |
255 - unrestricted |
| 86 |
|
| 87 |
|
| 88 |
Configuring Manual Discovery: |
| 89 |
Manual discovery is configured as per the following example: |
| 90 |
<cacheManagerPeerProviderFactory class= |
| 91 |
"net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" |
| 92 |
properties="peerDiscovery=manual, |
| 93 |
rmiUrls=//server1:40000/sampleCache1|//server2:40000/sampleCache1 |
| 94 |
| //server1:40000/sampleCache2|//server2:40000/sampleCache2"/> |
| 95 |
|
| 96 |
Valid properties are: |
| 97 |
* peerDiscovery (mandatory) - specify "manual" |
| 98 |
* rmiUrls (mandatory) - specify a pipe separated list of rmiUrls, in the form |
| 99 |
//hostname:port |
| 100 |
|
| 101 |
The hostname is the hostname of the remote CacheManager peer. The port is the listening |
| 102 |
port of the RMICacheManagerPeerListener of the remote CacheManager peer. |
| 103 |
|
| 104 |
<cacheManagerPeerProviderFactory |
| 105 |
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" |
| 106 |
properties="peerDiscovery=automatic, |
| 107 |
multicastGroupAddress=230.0.0.1, |
| 108 |
multicastGroupPort=4446, timeToLive=1"/> |
| 109 |
--> |
| 110 |
|
| 111 |
<!-- |
| 112 |
(Enable for distributed operation) |
| 113 |
|
| 114 |
Specifies a CacheManagerPeerListenerFactory which will be used to create a |
| 115 |
CacheManagerPeerListener, which |
| 116 |
listens for messages from cache replicators participating in the cluster. |
| 117 |
|
| 118 |
The attributes of cacheManagerPeerListenerFactory are: |
| 119 |
class - a fully qualified factory class name |
| 120 |
properties - comma separated properties having meaning only to the factory. |
| 121 |
|
| 122 |
Ehcache comes with a built-in RMI-based distribution system. The listener component is |
| 123 |
RMICacheManagerPeerListener which is configured using |
| 124 |
RMICacheManagerPeerListenerFactory. It is configured as per the following example: |
| 125 |
|
| 126 |
<cacheManagerPeerListenerFactory |
| 127 |
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" |
| 128 |
properties="hostName=fully_qualified_hostname_or_ip, |
| 129 |
port=40001, |
| 130 |
socketTimeoutMillis=120000"/> |
| 131 |
|
| 132 |
All properties are optional. They are: |
| 133 |
* hostName - the hostName of the host the listener is running on. Specify |
| 134 |
where the host is multihomed and you want to control the interface over which cluster |
| 135 |
messages are received. Defaults to the host name of the default interface if not |
| 136 |
specified. |
| 137 |
* port - the port the listener listens on. This defaults to a free port if not specified. |
| 138 |
* socketTimeoutMillis - the number of ms client sockets will stay open when sending |
| 139 |
messages to the listener. This should be long enough for the slowest message. |
| 140 |
If not specified it defaults 120000ms. |
| 141 |
|
| 142 |
<cacheManagerPeerListenerFactory |
| 143 |
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/> |
| 144 |
--> |
| 145 |
|
| 146 |
|
| 147 |
<!-- Cache configuration. |
| 148 |
|
| 149 |
The following attributes are required. |
| 150 |
|
| 151 |
name: |
| 152 |
Sets the name of the cache. This is used to identify the cache. It must be unique. |
| 153 |
|
| 154 |
maxElementsInMemory: |
| 155 |
Sets the maximum number of objects that will be created in memory (0 == no limit) |
| 156 |
|
| 157 |
maxElementsOnDisk: |
| 158 |
Sets the maximum number of objects that will be maintained in the DiskStore |
| 159 |
The default value is zero, meaning unlimited. |
| 160 |
|
| 161 |
eternal: |
| 162 |
Sets whether elements are eternal. If eternal, timeouts are ignored and the |
| 163 |
element is never expired. |
| 164 |
|
| 165 |
overflowToDisk: |
| 166 |
Sets whether elements can overflow to disk when the in-memory cache |
| 167 |
has reached the maxInMemory limit. |
| 168 |
|
| 169 |
The following attributes are optional. |
| 170 |
|
| 171 |
timeToIdleSeconds: |
| 172 |
Sets the time to idle for an element before it expires. |
| 173 |
i.e. The maximum amount of time between accesses before an element expires |
| 174 |
Is only used if the element is not eternal. |
| 175 |
Optional attribute. A value of 0 means that an Element can idle for infinity. |
| 176 |
The default value is 0. |
| 177 |
|
| 178 |
timeToLiveSeconds: |
| 179 |
Sets the time to live for an element before it expires. |
| 180 |
i.e. The maximum time between creation time and when an element expires. |
| 181 |
Is only used if the element is not eternal. |
| 182 |
Optional attribute. A value of 0 means that and Element can live for infinity. |
| 183 |
The default value is 0. |
| 184 |
|
| 185 |
diskPersistent: |
| 186 |
Whether the disk store persists between restarts of the Virtual Machine. |
| 187 |
The default value is false. |
| 188 |
|
| 189 |
diskExpiryThreadIntervalSeconds: |
| 190 |
The number of seconds between runs of the disk expiry thread. The default value |
| 191 |
is 120 seconds. |
| 192 |
|
| 193 |
diskSpoolBufferSizeMB: |
| 194 |
This is the size to allocate the DiskStore for a spool buffer. Writes are made |
| 195 |
to this area and then asynchronously written to disk. The default size is 30MB. |
| 196 |
Each spool buffer is used only by its cache. If you get OutOfMemory errors consider |
| 197 |
lowering this value. To improve DiskStore performance consider increasing it. Trace level |
| 198 |
logging in the DiskStore will show if put back ups are occurring. |
| 199 |
|
| 200 |
memoryStoreEvictionPolicy: |
| 201 |
Policy would be enforced upon reaching the maxElementsInMemory limit. Default |
| 202 |
policy is Least Recently Used (specified as LRU). Other policies available - |
| 203 |
First In First Out (specified as FIFO) and Less Frequently Used |
| 204 |
(specified as LFU) |
| 205 |
|
| 206 |
Cache elements can also contain sub elements which take the same format of a factory class |
| 207 |
and properties. Defined sub-elements are: |
| 208 |
|
| 209 |
* cacheEventListenerFactory - Enables registration of listeners for cache events, such as |
| 210 |
put, remove, update, and expire. |
| 211 |
|
| 212 |
* bootstrapCacheLoaderFactory - Specifies a BootstrapCacheLoader, which is called by a |
| 213 |
cache on initialisation to prepopulate itself. |
| 214 |
|
| 215 |
Each cache that will be distributed needs to set a cache event listener which replicates |
| 216 |
messages to the other CacheManager peers. For the built-in RMI implementation this is done |
| 217 |
by adding a cacheEventListenerFactory element of type RMICacheReplicatorFactory to each |
| 218 |
distributed cache's configuration as per the following example: |
| 219 |
|
| 220 |
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" |
| 221 |
properties="replicateAsynchronously=true, |
| 222 |
replicatePuts=true, |
| 223 |
replicateUpdates=true, |
| 224 |
replicateUpdatesViaCopy=true, |
| 225 |
replicateRemovals=true "/> |
| 226 |
|
| 227 |
The RMICacheReplicatorFactory recognises the following properties: |
| 228 |
|
| 229 |
* replicatePuts=true|false - whether new elements placed in a cache are |
| 230 |
replicated to others. Defaults to true. |
| 231 |
|
| 232 |
* replicateUpdates=true|false - whether new elements which override an |
| 233 |
element already existing with the same key are replicated. Defaults to true. |
| 234 |
|
| 235 |
* replicateRemovals=true - whether element removals are replicated. Defaults to true. |
| 236 |
|
| 237 |
* replicateAsynchronously=true | false - whether replications are |
| 238 |
asynchronous (true) or synchronous (false). Defaults to true. |
| 239 |
|
| 240 |
* replicateUpdatesViaCopy=true | false - whether the new elements are |
| 241 |
copied to other caches (true), or whether a remove message is sent. Defaults to true. |
| 242 |
|
| 243 |
|
| 244 |
* asynchronousReplicationIntervalMillis=<number of milliseconds> - The asynchronous |
| 245 |
replicator runs at a set interval of milliseconds. The default is 1000. The minimum |
| 246 |
is 10. This property is only applicable if replicateAsynchronously=true |
| 247 |
|
| 248 |
* asynchronousReplicationMaximumBatchSize=<number of operations> - The maximum |
| 249 |
number of operations that will be batch within a single RMI message. The default |
| 250 |
is 1000. This property is only applicable if replicateAsynchronously=true |
| 251 |
|
| 252 |
The RMIBootstrapCacheLoader bootstraps caches in clusters where RMICacheReplicators are |
| 253 |
used. It is configured as per the following example: |
| 254 |
|
| 255 |
<bootstrapCacheLoaderFactory |
| 256 |
class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" |
| 257 |
properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"/> |
| 258 |
|
| 259 |
The RMIBootstrapCacheLoaderFactory recognises the following optional properties: |
| 260 |
|
| 261 |
* bootstrapAsynchronously=true|false - whether the bootstrap happens in the background |
| 262 |
after the cache has started. If false, bootstrapping must complete before the cache is |
| 263 |
made available. The default value is true. |
| 264 |
|
| 265 |
* maximumChunkSizeBytes=<integer> - Caches can potentially be very large, larger than the |
| 266 |
memory limits of the VM. This property allows the bootstraper to fetched elements in |
| 267 |
chunks. The default chunk size is 5000000 (5MB). |
| 268 |
|
| 269 |
--> |
| 270 |
|
| 271 |
|
| 272 |
<!-- |
| 273 |
Mandatory Default Cache configuration. These settings will be applied to caches |
| 274 |
created programmtically using CacheManager.add(String cacheName) |
| 275 |
--> |
| 276 |
<defaultCache |
| 277 |
maxElementsInMemory="10000" |
| 278 |
eternal="false" |
| 279 |
timeToIdleSeconds="120" |
| 280 |
timeToLiveSeconds="120" |
| 281 |
maxElementsOnDisk="10000000" |
| 282 |
diskExpiryThreadIntervalSeconds="120" |
| 283 |
memoryStoreEvictionPolicy="LRU"> |
| 284 |
<persistence strategy="localTempSwap"/> |
| 285 |
</defaultCache> |
| 286 |
</ehcache> |