JPOX is developed as a plugin-driven framework and one of the components that is pluggable is the Level 2 caching
of objects (between PersistenceManagers for the same PersistenceManagerFactory). JPOX provides
a large selection of Level 2 caches (builtin, Tangosol, EHCache, OSCache, SwarmCache)
but is structured so that you can easily add your own variant and have it usable within your JPOX usage.
This is available in JPOX from version 1.1.2
JPOX is able to support third party Level 2 Cache products. There are JPOX-provided plugins for
EHCache, SwarmCache, OSCache, and Tangosol Coherence. You can extend JPOX's capabilities using the
plugin extension org.jpox.cache_level2.
| Plugin extension-point | Key | Description | Location |
|---|
| org.jpox.cache_level2 | default | Level 2 Cache (default) | jpox-core |
| org.jpox.cache_level2 | soft | Level 2 Cache using Soft maps | jpox-core |
| org.jpox.cache_level2 | ehcache | Level 2 Cache using EHCache | jpox-ehcache |
| org.jpox.cache_level2 | ehcacheclassbased | Level 2 Cache using EHCache (based on classes) | jpox-ehcache |
| org.jpox.cache_level2 | oscache | Level 2 Cache using OSCache | jpox-oscache |
| org.jpox.cache_level2 | swarmcache | Level 2 Cache using SwarmCache | jpox-swarmcache |
| org.jpox.cache_level2 | tangosol | Level 2 Cache using Tangosol Coherence | jpox-tangosol |
The following sections describe how to create your own Level 2 cache plugin for JPOX.
If you have your own Level2 cache you can easily use it with JPOX.
JPOX defines a Level2Cache interface and you need to implement this.
package javax.jdo.datastore;
public interface DataStoreCache
{
void evict (Object oid);
void evictAll ();
void evictAll (Object[] oids);
void evictAll (Collection oids);
void evictAll (Class pcClass, boolean subclasses);
void pin (Object oid);
void pinAll (Collection oids);
void pinAll (Object[] oids);
void pinAll (Class pcClass, boolean subclasses);
void unpin(Object oid);
void unpinAll(Collection oids);
void unpinAll(Object[] oids);
void unpinAll(Class pcClass, boolean subclasses);
}
package org.jpox.cache;
public interface Level2Cache extends javax.jdo.datastore.DataStoreCache
{
int getNumberOfPinnedObjects();
int getNumberOfUnpinnedObjects();
int getSize();
CachedPC get(Object oid);
CachedPC put(Object oid, CachedPC pc);
boolean isEmpty();
void clear();
}
Once you have this implementation you then need to make the class available as a JPOX 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" name="JPOX plug-ins" provider-name="My Company">
<extension point="org.jpox.cache_level2">
<cache name="MyCache" class-name="mydomain.MyLevel2Cache"/>
</extension>
</plugin>
The only thing remaining is to use your L2 Cache plugin. To do this you specify the
PersistenceManagerFactory property org.jpox.cache.level2.type
as MyCache (the "name" in plugin.xml).
In JPOX 1.1.2 the "extension point" was "org.jpox.cache", but in 1.1.3 and later it is
changed to "org.jpox.cache_level2"