DataNucleus is developed as a plugin-driven framework and one of the components that is pluggable is the Level 1 caching of objects (between PersistenceManagers for the same PersistenceManagerFactory). The Cache guide (JDO or JPA) defines three Level 1 caches but is a plugin point so that you can easily add your own variant and have it usable within your DataNucleus usage.
DataNucleus is able to support third party Level 1 Cache products. There are DataNucleus-provided plugins for weak and soft referenced caches. You can extend DataNucleus's capabilities using the plugin extension org.datanucleus.cache_level1.
| Plugin extension-point | Key | Description | Location |
|---|---|---|---|
| org.datanucleus.cache_level1 | weak | Weak referenced cache (default) | datanucleus-core |
| org.datanucleus.cache_level1 | soft | Soft referenced cache | datanucleus-core |
| org.datanucleus.cache_level1 | hard | Hard-referenced cache (HashMap) | datanucleus-core |
The following sections describe how to create your own Level 1 cache plugin for DataNucleus.
If you have your own Level1 cache you can easily use it with DataNucleus.
DataNucleus defines a Level1Cache interface and you need to implement this.
package org.datanucleus.cache;
public interface Level1Cache extends Map
{
}So you need to create a class, MyLevel1Cache for example, that implements this interface (i.e that implements java.util.Map).
Once you have this implementation you then need to make the class available as a DataNucleus plugin. You do this by putting a file plugin.xml in your JAR at the root of the CLASSPATH. The file plugin.xml will look like this
<?xml version="1.0"?>
<plugin id="mydomain.mycache" name="DataNucleus plug-ins" provider-name="My Company">
<extension point="org.datanucleus.cache_level1">
<cache name="MyCache" class-name="mydomain.MyLevel1Cache"/>
</extension>
</plugin>Note that you also require a MANIFEST.MF file as per the Plugins Guide.