JDO L2 Cache SingleFieldIdentity

231 Views Asked by At

I'm trying to enable L2 cache in my JDO installation. Spring configuration is:

<prop key="datanucleus.cache.level2.type">spymemcached</prop>
<prop key="datanucleus.cache.level2.memcached.servers">localhost:11211</prop>

so prefix is default "datanucleus".

The problem is that any object with SingleFieldIdentity is represented by key "datanucleus###" where ### is string representation of that identity WITHOUT class name in that key.

Sample class:

@PersistenceCapable(detachable="true", table="sites", cacheable="true")
public class Site 
implements Serializable {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    public Long id;
}

I have another cacheable classes, for example Account. Account with id 7 is stored to memecached as "datanucleus7", so when a site with id=7 is pulled from cache everything is screwed up.

In datanucleus cache package there is a class SpymemcachedLevel2Cache (SpymemcachedLevel2Cache.java):

public class SpymemcachedLevel2Cache extends AbstractLevel2Cache
{
...
    public CachedPC get(Object oid)
    {
        return (CachedPC) client.get(cacheName + oid.toString());
    }
...
}

But oid.toString() for SingleFieldIdentity(e.g. LongIdentity) is a simple number with no class information.

So the question is: how can I change that behavior? Should I reimplement SpymemcachedLevel2Cache using

if (nucleusCtx.getApiAdapter().isSingleFieldIdentity(id))
    {
        String targetClassName = nucleusCtx.getApiAdapter().getTargetClassNameForSingleFieldIdentity(id);
    ...
1

There are 1 best solutions below

0
On

Included that functionality in DataNucleus yesterday. SVN trunk has it