3.11.1.1.3. Distributing instances across cache partitions

OpenJPA also supports a partitioned cache configuration where the cached instances can be distributed across partitions by an application-defined policy. Each partition behaves as a data cache by itself, identified by its name and can be configured individually. The distribution policy determines the specific partition that stores the state of a managed instance. The default distribution policy distributes the instances by their type as specified by the name attribute in @DataCache annotation. Cache distribution policy is a simple interface that can be implemented by an application to distribute among the partitions on a per instance basis. To enable a partitioned cache set the openjpa.DataCache property to partitioned, and configure individual partitions as follows:

Example 145. Partitioned Data Cache
<property name="openjpa.CacheDistributionPolicy" value="org.acme.foo.DistributionPolicy"/>
<property name="openjpa.DataCache" value="partitioned(PartitionType=concurrent,partitions=
                '(name=a,cacheSize=100),(name=b,cacheSize=200)')"/>

The distribution policy is configured by a full-qualified class name that implements org.apache.openjpa.datacahe.CacheDistributionPolicy. The partitions are specified as value of the partitions attribute as a series of individually configurable plug-in strings. As the example shows, i) each partition plug-in configuration must be enclosed in parentheses, ii) must be separated by comma and iii) the complete set be enclosed in single quote. Each individual partition is a Data Cache by itself and the class that implements the partition can be configured via PartitionType attribute. The above example configuration will configure a partitioned cache with two partitions named a and b of cache size 100 and 200, respectively. The partitions are of concurrent type which is a mnemonic or alias for org.apache.openjpa.datacache.ConcurrentDataCache. The PartitionType is defaulted to concurrent though explicitly mentioned in this example.