Configuring Distributed DataNucleus L2 Cache

Contents

The DataNucleus Access Platform provides persistence and retrieval of data to a range of datastores using standard JPA and JDO APIs. DataNucleus has developed native integration with Cacheonix. Cacheonix DataNucleus L2 cache offers developers practically unlimited scalability by providing reliable distributed data management, sharing and replicating of cached data in a cluster of servers connected by a high-speed local network.

Setting up Cacheonix DataNucleus L2 cache is very easy and includes the following steps:

  1. Downloading Cacheonix
  2. Configuring Cacheonix
  3. Configuring DataNucleus

The following sections discuss configuring Cacheonix DataNucleus L2 cache in detail.

Downloading Cacheonix

Visit Downloads section of Cacheonix website to download cacheonix.jar. Include the downloaded cacheonix.jar in the classpath. Web applications must put cacheonix.jar in the directory WEB-INF/lib.

Configuring Cacheonix

Cacheonix is configured using an XML file cacheonix-config.xml that should be included in the classpath. The best location for cacheonix-config.xml in a web application is a directory WEB-INF/classes. Cacheonix configuration for DataNucleus includes a catch-all cache configuration named "default". Cacheonix will use the default configuration as a template to automatically create DataNucleus caches. In this case DataNucleus will create a cache of the same configuration for each namespace. The benefit of this approach is that only a single cache configuration needs to be maintained. The example below demonstrates cacheonix-config.xml for the clustered environment using the template configuration:

<?xml version ="1.0"?>
<cacheonix xmlns="http://www.cacheonix.com/schema/configuration"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.cacheonix.com/schema/configuration http://www.cacheonix.com/schema/cacheonix-config-2.0.xsd">

   <licensePath path="META-INF/cacheonix-license.xml"/>

   <server>

      <listener>
         <tcp port="8879"buffer="128k"/>
      </listener>

      <broadcast>
         <multicast multicastAddress="225.0.1.2" multicastPort="9998 "multicastTTL="1"/>
      </broadcast>

      <!-- One cache per class being stored. -->
      <partitionedCachename="mydomain.MyClass">
         <store>
            <lru maxElements="1000" maxBytes="1mb"/>
            <expiration timeToLive="60s"/>
      </store>
      </partitionedCache>

      <!-- Fallback cache for classes indeterminable from their id. -->
      <partitionedCachename="datanucleus">
         <store>
            <lru maxElements="1000" maxBytes="10mb"/>
            <expiration timeToLive="60s"/>
         </store>
      </partitionedCache>

      <partitionedCachename="default" template="true">
         <store>
            <lru maxElements="10" maxBytes="10mb"/>
            <overflowToDisk maxOverflowBytes="1mb"/>
            <expiration timeToLive="1s"/>
         </store>
      </partitionedCache>
   </server>
</cacheonix>

Configuring Data Nucleus

DataNucleus provides a simple wrapper to Cacheonix. To enable using Cacheonix as a DataNucleus L2 Cache, set the persistence properties as follows:

datanucleus.cache.level2.type=cacheonix
datanucleus.cache.level2.cacheName={cache name}

Note that you can optionally also specify a timeout and a location of the Cacheonix configuration file in case it is other than default:

datanucleus.cache.level2.timeout={timeout-in-millis (default=60)}
datanucleus.cache.level2.configurationFile={Cacheonix configuration file (in classpath)}

See Also:

Labels

 
(None)