我正在尝试在我的L2安装中启用JDO缓存。Spring配置为:
<prop key="datanucleus.cache.level2.type">spymemcached</prop>
<prop key="datanucleus.cache.level2.memcached.servers">localhost:11211</prop>所以前缀是默认的"datanucleus“。
问题是任何带有SingleFieldIdentity的对象都由键"datanucleus###“表示,其中###是该标识的字符串表示,键中没有类名。
示例类:
@PersistenceCapable(detachable="true", table="sites", cacheable="true")
public class Site
implements Serializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
public Long id;
}我还有另一个可缓存的类,例如Account。id为7的帐号作为"datanucleus7“存储到memecached中,所以当一个带有id=7的站点从缓存中被拉出来时,一切都搞砸了。
在datanucleus缓存包中有一个类SpymemcachedLevel2Cache (SpymemcachedLevel2Cache.java):
public class SpymemcachedLevel2Cache extends AbstractLevel2Cache
{
...
public CachedPC get(Object oid)
{
return (CachedPC) client.get(cacheName + oid.toString());
}
...
}但是SingleFieldIdentity的oid.toString() (例如LongIdentity)是一个没有类信息的简单数字。
所以问题是:我如何才能改变这种行为?我是否应该使用以下命令重新实现SpymemcachedLevel2Cache
if (nucleusCtx.getApiAdapter().isSingleFieldIdentity(id))
{
String targetClassName = nucleusCtx.getApiAdapter().getTargetClassNameForSingleFieldIdentity(id);
...发布于 2011-10-14 01:22:47
昨天在DataNucleus中包含了这一功能。SVN中继线有它
https://stackoverflow.com/questions/7730250
复制相似问题