All Downloads are FREE. Search and download functionalities are using the official Maven repository.

caching.ehcache-config.xml Maven / Gradle / Ivy

There is a newer version: 8.0
Show newest version
<?xml version="1.0" encoding="UTF-8"?>
<!--

    The contents of this file are subject to the license and copyright
    detailed in the LICENSE and NOTICE files at the root of the source
    tree and available online at

    http://www.dspace.org/license/

-->
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">

    <!-- Sets the path to the directory where cache .data files are created.

         If the path is a Java System Property it is replaced by
         its value in the running VM.

         The following properties are translated:
         user.home - User's home directory
         user.dir - User's current working directory
         java.io.tmpdir - Default temp file path -->

    <diskStore path="java.io.tmpdir"/>


    <!--
    Cache configuration
    ===================

    The following attributes are required.

    name:
    Sets the name of the cache. This is used to identify the cache. It must be unique.

    maxElementsInMemory:
    Sets the maximum number of objects that will be created in memory

        maxElementsOnDisk:
    Sets the maximum number of objects that will be maintained in the DiskStore
        The default value is zero, meaning unlimited.

    eternal:
    Sets whether elements are eternal. If eternal,  timeouts are ignored and the
    element is never expired.

    overflowToDisk:
    Sets whether elements can overflow to disk when the memory store
    has reached the maxInMemory limit.

    The following attributes and elements are optional.

    timeToIdleSeconds:
    Sets the time to idle for an element before it expires.
    i.e. The maximum amount of time between accesses before an element expires
    Is only used if the element is not eternal.
    Optional attribute. A value of 0 means that an Element can idle for infinity.
    The default value is 0.

    timeToLiveSeconds:
    Sets the time to live for an element before it expires.
    i.e. The maximum time between creation time and when an element expires.
    Is only used if the element is not eternal.
    Optional attribute. A value of 0 means that and Element can live for infinity.
    The default value is 0.

    diskPersistent:
    Whether the disk store persists between restarts of the Virtual Machine.
    The default value is false.

    diskExpiryThreadIntervalSeconds:
    The number of seconds between runs of the disk expiry thread. The default value
    is 120 seconds.

    diskSpoolBufferSizeMB:
    This is the size to allocate the DiskStore for a spool buffer. Writes are made
    to this area and then asynchronously written to disk. The default size is 30MB.
    Each spool buffer is used only by its cache. If you get OutOfMemory errors consider
    lowering this value. To improve DiskStore performance consider increasing it. Trace level
    logging in the DiskStore will show if put back ups are occurring.

    memoryStoreEvictionPolicy:
    Policy would be enforced upon reaching the maxElementsInMemory limit. Default
    policy is Least Recently Used (specified as LRU). Other policies available -
    First In First Out (specified as FIFO) and Less Frequently Used
    (specified as LFU)
    *NOTE: LFU seems to have some possible issues -AZ

    Cache elements can also contain sub elements which take the same format of a factory class
    and properties. Defined sub-elements are:

    * cacheEventListenerFactory - Enables registration of listeners for cache events, such as
      put, remove, update, and expire.

    * bootstrapCacheLoaderFactory - Specifies a BootstrapCacheLoader, which is called by a
      cache on initialisation to prepopulate itself.

    * cacheExtensionFactory - Specifies a CacheExtension, a generic mechansim to tie a class
      which holds a reference to a cache to the cache lifecycle.

    RMI Cache Replication

    Each cache that will be distributed needs to set a cache event listener which replicates
    messages to the other CacheManager peers. For the built-in RMI implementation this is done
    by adding a cacheEventListenerFactory element of type RMICacheReplicatorFactory to each
    distributed cache's configuration as per the following example:

    <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
         properties="replicateAsynchronously=true,
         replicatePuts=true,
         replicateUpdates=true,
         replicateUpdatesViaCopy=true,
         replicateRemovals=true
         asynchronousReplicationIntervalMillis=<number of milliseconds"
         propertySeparator="," />

    The RMICacheReplicatorFactory recognises the following properties:

    * replicatePuts=true|false - whether new elements placed in a cache are
      replicated to others. Defaults to true.

    * replicateUpdates=true|false - whether new elements which override an
      element already existing with the same key are replicated. Defaults to true.

    * replicateRemovals=true - whether element removals are replicated. Defaults to true.

    * replicateAsynchronously=true | false - whether replications are
      asynchronous (true) or synchronous (false). Defaults to true.

    * replicateUpdatesViaCopy=true | false - whether the new elements are
      copied to other caches (true), or whether a remove message is sent. Defaults to true.

    * asynchronousReplicationIntervalMillis=<number of milliseconds> - The asynchronous
      replicator runs at a set interval of milliseconds. The default is 1000. The minimum
      is 10. This property is only applicable if replicateAsynchronously=true


    Cluster Bootstrapping

    The RMIBootstrapCacheLoader bootstraps caches in clusters where RMICacheReplicators are
    used. It is configured as per the following example:

    <bootstrapCacheLoaderFactory
        class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
        properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"
        propertySeparator="," />

    The RMIBootstrapCacheLoaderFactory recognises the following optional properties:

    * bootstrapAsynchronously=true|false - whether the bootstrap happens in the background
      after the cache has started. If false, bootstrapping must complete before the cache is
      made available. The default value is true.

    * maximumChunkSizeBytes=<integer> - Caches can potentially be very large, larger than the
      memory limits of the VM. This property allows the bootstraper to fetched elements in
      chunks. The default chunk size is 5000000 (5MB).


    Cache Exception Handling

    By default, most cache operations will propagate a runtime CacheException on failure. An interceptor,
      using a dynamic proxy, may be configured so that a CacheExceptionHandler can be configured to
      intercept Exceptions. Errors are not intercepted. It is configured as per the following example:

      <cacheExceptionHandlerFactory class="net.sf.ehcache.exceptionhandler.CountingExceptionHandlerFactory"
                                      properties="logLevel=FINE"/>

    Caches with ExceptionHandling configured are not of type Cache, but are of type Ehcache only, and are not available
    using CacheManager.getCache(), but using CacheManager.getEhcache().


    CacheLoader

    A CacheLoader may be configured against a cache.

        <cacheLoaderFactory class="net.sf.ehcache.loader.CountingCacheLoaderFactory"
                                      properties="type=int,startCounter=10"/>

    -->

    <!--
    Mandatory Default Cache configuration. These settings will be applied to caches
    created programmtically using CacheManager.add(String cacheName).

    The defaultCache has an implicit name "default" which is a reserved cache name.
    -->
    <defaultCache
         maxElementsInMemory="3000"
         eternal="false"
         timeToIdleSeconds="600"
         timeToLiveSeconds="1200"
         overflowToDisk="true"
         diskSpoolBufferSizeMB="30"
         maxElementsOnDisk="10000"
         diskPersistent="false"
         diskExpiryThreadIntervalSeconds="120"
         memoryStoreEvictionPolicy="LRU">
     </defaultCache>


    <!--Predefined caches.  Add your cache configuration settings here.
        If you do not have a configuration for your cache a WARNING will be issued when the
        CacheManager starts

        The following attributes are required for defaultCache:

        name              - Sets the name of the cache. This is used to identify the cache. It must be unique.
        maxInMemory       - Sets the maximum number of objects that will be created in memory
        eternal           - Sets whether elements are eternal. If eternal,  timeouts are ignored and the element
                            is never expired.
        timeToIdleSeconds - Sets the time to idle for an element before it expires.
                            i.e. The maximum amount of time between accesses before an element expires
                            Is only used if the element is not eternal.
                            Optional attribute. A value of 0 means that an Element can idle for infinity
        timeToLiveSeconds - Sets the time to live for an element before it expires.
                            i.e. The maximum time between creation time and when an element expires.
                            Is only used if the element is not eternal.
                            Optional attribute. A value of 0 means that an Element can live for infinity
        overflowToDisk    - Sets whether elements can overflow to disk when the in-memory cache
                            has reached the maxInMemory limit.

        -->

    <!-- CACHES FOR TESTING -->
<!-- 
    <cache name="org.dspace.caching.MemOnly"
         maxElementsInMemory="10000"
         eternal="false"
         timeToIdleSeconds="600"
         timeToLiveSeconds="1200"
         overflowToDisk="false"
         diskSpoolBufferSizeMB="0"
         maxElementsOnDisk="0"
         diskPersistent="false"
         diskExpiryThreadIntervalSeconds="120"
         memoryStoreEvictionPolicy="LRU">
     </cache>

    <cache name="org.dspace.caching.DiskOnly"
         maxElementsInMemory="1"
         eternal="false"
         timeToIdleSeconds="600"
         timeToLiveSeconds="1200"
         overflowToDisk="true"
         diskSpoolBufferSizeMB="30"
         maxElementsOnDisk="10000"
         diskPersistent="false"
         diskExpiryThreadIntervalSeconds="120"
         memoryStoreEvictionPolicy="LRU">
     </cache>

    <cache name="org.dspace.caching.Distributed"
         maxElementsInMemory="10"
         eternal="false"
         timeToIdleSeconds="10"
         timeToLiveSeconds="30"
         overflowToDisk="false"
         memoryStoreEvictionPolicy="LRU">
         <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" 
            properties="replicateAsynchronously=true, 
               replicatePuts=true, 
               replicateUpdates=true, 
               replicateUpdatesViaCopy=false, 
               replicateRemovals=true "/>
     </cache>

    <cache name="org.dspace.caching.DistributedDisk"
         maxElementsInMemory="5"
         eternal="false"
         timeToIdleSeconds="10"
         timeToLiveSeconds="30"
         overflowToDisk="true"
         diskSpoolBufferSizeMB="30"
         maxElementsOnDisk="10"
         diskPersistent="false"
         diskExpiryThreadIntervalSeconds="120"
         memoryStoreEvictionPolicy="LRU">
         <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" 
            properties="replicateAsynchronously=true, 
               replicatePuts=true, 
               replicateUpdates=true, 
               replicateUpdatesViaCopy=false, 
               replicateRemovals=true "/>
     </cache>
-->

   <!-- Place configuration for your caches following -->

   <!-- this cache tracks the timestamps of the most recent updates to particular tables. 
     It is important that the cache timeout of the underlying cache implementation be set to a 
     higher value than the timeouts of any of the query caches. In fact, it is recommended that 
     the the underlying cache not be configured for expiry at all. -->
<!--   <cache name="org.hibernate.cache.UpdateTimestampsCache"-->
<!--      maxElementsInMemory="6000"-->
<!--      eternal="true"-->
<!--      overflowToDisk="false" />-->

    <!-- this cache stores the actual objects pulled out of the DB by hibernate -->
<!--    <cache name="org.hibernate.cache.StandardQueryCache"-->
<!--      maxElementsInMemory="12000"-->
<!--      eternal="false"-->
<!--      timeToIdleSeconds="600"-->
<!--      timeToLiveSeconds="1200"-->
<!--      overflowToDisk="false" />-->


<!-- DISTRIBUTED CACHING

    Add cacheEventListenerFactory to the cache
    ==========================================
         <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" 
            properties="replicateAsynchronously=true, 
               replicatePuts=true, 
               replicateUpdates=true, 
               replicateUpdatesViaCopy=false, 
               replicateRemovals=true "/>
    
    For Example:
    ============
    <cache name="org.dspace.authz.api.SecurityService.cache"
         maxElementsInMemory="20000"
         eternal="false"
         timeToIdleSeconds="1800"
         timeToLiveSeconds="2400"
         overflowToDisk="true"
         diskSpoolBufferSizeMB="30"
         maxElementsOnDisk="100000"
         diskPersistent="true"
         diskExpiryThreadIntervalSeconds="120">
         <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" 
            properties="replicateAsynchronously=true, 
               replicatePuts=true, 
               replicateUpdates=true, 
               replicateUpdatesViaCopy=false, 
               replicateRemovals=true "/>
   </cache>


    CacheManagerPeerProvider
    ========================
    (Enable for distributed operation)

    Specifies a CacheManagerPeerProviderFactory which will be used to create a
    CacheManagerPeerProvider, which discovers other CacheManagers in the cluster.

    The attributes of cacheManagerPeerProviderFactory are:
    * class - a fully qualified factory class name
    * properties - comma separated properties having meaning only to the factory.

    Ehcache comes with a built-in RMI-based distribution system with two means of discovery of
    CacheManager peers participating in the cluster:
    * automatic, using a multicast group. This one automatically discovers peers and detects
      changes such as peers entering and leaving the group
    * manual, using manual rmiURL configuration. A hardcoded list of peers is provided at
      configuration time.

    Configuring Automatic Discovery:
    Automatic discovery is configured as per the following example:
    <cacheManagerPeerProviderFactory
                        class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
                        properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
                                    multicastGroupPort=4446, timeToLive=32"/>

    Valid properties are:
    * peerDiscovery (mandatory) - specify "automatic"
    * multicastGroupAddress (mandatory) - specify a valid multicast group address
    * multicastGroupPort (mandatory) - specify a dedicated port for the multicast heartbeat
      traffic
    * timeToLive - specify a value between 0 and 255 which determines how far the packets will propagate.
      By convention, the restrictions are:
      0   - the same host
      1   - the same subnet
      32  - the same site
      64  - the same region
      128 - the same continent
      255 - unrestricted

    Configuring Manual Discovery:
    Manual discovery is configured as per the following example:
    <cacheManagerPeerProviderFactory class=
                          "net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
                          properties="peerDiscovery=manual,
                          rmiUrls=//server1:40000/sampleCache1|//server2:40000/sampleCache1
                          | //server1:40000/sampleCache2|//server2:40000/sampleCache2"
                          propertySeparator="," />

    Valid properties are:
    * peerDiscovery (mandatory) - specify "manual"
    * rmiUrls (mandatory) - specify a pipe separated list of rmiUrls, in the form
                            //hostname:port

    The hostname is the hostname of the remote CacheManager peer. The port is the listening
    port of the RMICacheManagerPeerListener of the remote CacheManager peer.

    <cacheManagerPeerProviderFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
            properties="peerDiscovery=automatic,
                        multicastGroupAddress=230.0.0.1,
                        multicastGroupPort=4446, timeToLive=1"
            propertySeparator=","
            />
    -->

    <!--
    CacheManagerPeerListener
    ========================
    (Enable for distributed operation)

    Specifies a CacheManagerPeerListenerFactory which will be used to create a
    CacheManagerPeerListener, which
    listens for messages from cache replicators participating in the cluster.

    The attributes of cacheManagerPeerListenerFactory are:
    class - a fully qualified factory class name
    properties - comma separated properties having meaning only to the factory.

    Ehcache comes with a built-in RMI-based distribution system. The listener component is
    RMICacheManagerPeerListener which is configured using
    RMICacheManagerPeerListenerFactory. It is configured as per the following example:

    <cacheManagerPeerListenerFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="hostName=fully_qualified_hostname_or_ip,
                    port=40001,
                    socketTimeoutMillis=120000"
                    propertySeparator="," />

    All properties are optional. They are:
    * hostName - the hostName of the host the listener is running on. Specify
      where the host is multihomed and you want to control the interface over which cluster
      messages are received. Defaults to the host name of the default interface if not
      specified.
    * port - the port the listener listens on. This defaults to a free port if not specified.
    * socketTimeoutMillis - the number of ms client sockets will stay open when sending
      messages to the listener. This should be long enough for the slowest message.
      If not specified it defaults 120000ms.
    * timeToLive - You can control how far the multicast packets propagate by setting the 
    badly misnamed time to live. Using the multicast IP protocol, the timeToLive value 
    indicates the scope or range in which a packet may be forwarded. By convention:
        0 is restricted to the same host
        1 is restricted to the same subnet
        32 is restricted to the same site
        64 is restricted to the same region
        128 is restricted to the same continent
        255 is unrestricted

    <cacheManagerPeerListenerFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/>
    -->

   <!-- Sample Distributed cache settings -->


   <!-- Option A: automatic discovery using tcp multicast
        For the multicast version, the IP address is no longer that of the server. 
        Rather, you need to choose the address and port in a designated range that has been reserved for multicasting. 
        It is as if the server and all potential clients are agreeing that messages will be left in a particular location. 
        The available addresses for multicasting are in the range 224.0.0.0 through 239.255.255.255. 
        You can check for the assigned addresses in this range (http://www.iana.org/assignments/multicast-addresses). 
        Recommended default is to use the IP address 230.0.0.1 and the port 4446.

   <cacheManagerPeerProviderFactory
      class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
      properties="peerDiscovery=automatic, 
         multicastGroupAddress=230.0.0.1,
         multicastGroupPort=4446, 
         timeToLive=1" />
    -->



   <!-- Option B: manual discovery (you must customize this to include every node in the cluster) -->
<!--
   <cacheManagerPeerProviderFactory
      class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
      properties="peerDiscovery=manual,
      rmiUrls=//server2:40001/sampleCache11|//server2:40001/sampleCache12" />
-->


    <!-- 
        A CacheManagerPeerListener listens for messages from peers to the current CacheManager.
        
        You configure the CacheManagerPeerListener by specifiying a CacheManagerPeerListenerFactory which is used to create 
        the CacheManagerPeerListener using the plugin mechanism.
        
        The attributes of cacheManagerPeerListenerFactory are:
        * class - a fully qualified factory class name 
        * properties - comma separated properties having meaning only to the factory.
        
        Ehcache comes with a built-in RMI-based distribution system. The listener component is RMICacheManagerPeerListener 
        which is configured using RMICacheManagerPeerListenerFactory. It is configured as per the following example:
        
        <cacheManagerPeerListenerFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
            properties="hostName=localhost, port=40001, socketTimeoutMillis=2000" />
        
        Valid properties are:
        * hostName (optional) - the hostName of the host the listener is running on. Specify where the host is 
            multihomed and you want to control the interface over which cluster messages are received.
            
            The hostname is checked for reachability during CacheManager initialisation.
            
            If the hostName is unreachable, the CacheManager will refuse to start and an CacheException will be thrown 
            indicating connection was refused.
            
            If unspecified, the hostname will use InetAddress.getLocalHost().getHostAddress(), which corresponds to the 
            default host network interface.
            
            Warning: Explicitly setting this to localhost refers to the local loopback of 127.0.0.1, which is not network 
            visible and will cause no replications to be received from remote hosts. You should only use this setting when 
            multiple CacheManagers are on the same machine.

            NOTE: this is not obvious, but if you run a netstat -an | grep LISTEN you will see that the configuration shown below:
            properties="hostName=127.0.0.1, port=40001"
            will actually cause a bind to happen to *:40001 which is what we want and will allow the servers to start
            even if there is no netowkr connection. On the other hand, if you use localhost there will be a resolution
            failure on startup. This is probably what you should use regardless of the setup of the peer provider factory. -AZ
        * port (mandatory) - the port the listener listens on.
        * socketTimeoutMillis (optional) - the number of seconds client sockets will wait when sending messages to this 
            listener until they give up. By default this is 2000ms.
    -->

    <!-- For Distributed Caching in a cluster, this will listen for the messages from peers
    <cacheManagerPeerListenerFactory
      class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
      properties="hostName=127.0.0.1, port=40001" />
    -->

</ehcache>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy