import java.util.Collection;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
this.cacheId = cacheId;
cache = new Cache(getEntityCacheConfiguration(cacheId));
- CdmRemoteCacheManager.getInstance().getDefaultCacheManager().addCache(cache);
-
this.cdmEntitySessionManager = cdmEntitySessionManager;
- CdmBase fromCache = cdmServiceCacher.getFromCache(UUID.fromString("462a7819-8b00-4190-8313-88b5be81fad5"));
-
- cacheLoader = new CacheLoader(this, cdmServiceCacher);
+ cacheLoader = new CacheLoader(this);
+ }
+ public CdmTransientEntityCacher(Object sessionOwner, ICdmEntitySessionManager cdmEntitySessionManager) {
+ this(generateCacheId(sessionOwner), cdmEntitySessionManager);
}
- public CdmTransientEntityCacher(Object obj, ICdmEntitySessionManager cdmEntitySessionManager) {
- this(obj.getClass().getName() + String.valueOf(obj.hashCode()), cdmEntitySessionManager);
+ public static String generateCacheId(Object sessionOwner) {
+ return sessionOwner.getClass().getName() + String.valueOf(sessionOwner.hashCode());
}
/**
return;
}
CdmEntityCacheKey id = new CdmEntityCacheKey(cdmEntity);
- getCache().put(new Element(id, cdmEntity));
+
+ cachedCdmEntity = getFromCache(id);
+ if(cachedCdmEntity == null) {
+ getCache().put(new Element(id, cdmEntity));
+ logger.info(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " put in cache");
+ return;
+ }
+ logger.info(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " already exists");
}
if(cachedCdmEntity == null) {
// ... then try the permanent cache
- cachedCdmEntity = cdmServiceCacher.getFromCache(cdmBase);
+ cachedCdmEntity = cdmServiceCacher.getFromCache(cdmBase.getUuid());
}
return cachedCdmEntity;
public void dispose() {
cache.dispose();
- CdmRemoteCacheManager.getInstance().getDefaultCacheManager().removeCache(cacheId);
+
}