1 回答

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊
沒(méi)有官方或社區(qū)項(xiàng)目支持它。
但是,您可以實(shí)現(xiàn)自己的CacheInterceptor。
例如。
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.internal.identitymaps.CacheKey;
import org.eclipse.persistence.internal.identitymaps.IdentityMap;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.sessions.interceptors.CacheInterceptor;
import org.eclipse.persistence.sessions.interceptors.CacheKeyInterceptor;
import java.util.Map;
public class MyRedisCacheInterceptor extends CacheInterceptor {
? ? private final MyCacheProvider cacheSupport;
? ? private final String cacheName;
? ? public DefaultCacheInterceptor(IdentityMap targetIdentityMap, AbstractSession interceptedSession,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?String cacheName, DefaultCacheSupport cacheSupport) {
? ? ? ? super(targetIdentityMap, interceptedSession);
? ? ? ? this.cacheSupport = cacheSupport;
? ? ? ? this.cacheName = cacheName;
? ? }
? ? @Override
? ? public Object clone() {
? ? ? ? return null;
? ? }
? ? @Override
? ? protected CacheKeyInterceptor createCacheKeyInterceptor(CacheKey wrappedCacheKey) {
? ? ? ? final long longKey = (long) wrappedCacheKey.getKey();
? ? ? ? CacheKeyInterceptor newKey = new CacheKeyInterceptor(wrappedCacheKey) {
? ? ? ? ? ? @Override
? ? ? ? ? ? public Object getObject() {
? ? ? ? ? ? ? ? return cacheSupport.getOrCreateCache(cacheName).get(longKey);
? ? ? ? ? ? }
? ? ? ? ? ? @Override
? ? ? ? ? ? public void setObject(Object object) {
? ? ? ? ? ? ? ? cacheSupport.getOrCreateCache(cacheName).put(longKey, object);
? ? ? ? ? ? }
? ? ? ? };
? ? ? ? return newKey;
? ? }
? ? @Override
? ? public boolean containsKey(Object primaryKey) {
? ? ? ? return cacheSupport.getOrCreateCache(cacheName).containsKey(primaryKey);
? ? }
? ? @Override
? ? public Map<Object, Object> getAllFromIdentityMapWithEntityPK(Object[] pkList, ClassDescriptor descriptor, AbstractSession session) {
? ? ? ? return null;
? ? }
? ? @Override
? ? public Map<Object, CacheKey> getAllCacheKeysFromIdentityMapWithEntityPK(Object[] pkList, ClassDescriptor descriptor, AbstractSession session) {
? ? ? ? return null;
? ? }
? ? @Override
? ? public void release() {
? ? }
}
添加回答
舉報(bào)