diff --git a/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java b/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java index 4f3301be..9aabc1c4 100644 --- a/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java +++ b/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java @@ -59,7 +59,7 @@ public class EntityCache, E extends IEntity> imple private final EntityDef entityDef; - private final LazyCache> cache; + private final LazyCache> cache; private ICacheVersion cacheVersion = new CacheVersionDefault<>(); @@ -75,9 +75,9 @@ public class EntityCache, E extends IEntity> imple cacheVersion = new CacheVersion<>(filed.getName(), getMethod, setMethod); } - var removeCallback = new BiConsumer>, LazyCache.RemovalCause>() { + var removeCallback = new BiConsumer>, LazyCache.RemovalCause>() { @Override - public void accept(Pair> pair, LazyCache.RemovalCause removalCause) { + public void accept(Pair> pair, LazyCache.RemovalCause removalCause) { if (removalCause == LazyCache.RemovalCause.EXPLICIT) { return; } @@ -176,7 +176,7 @@ public class EntityCache, E extends IEntity> imple /** * 校验需要更新的entity和缓存的entity是否为同一个entity */ - private PNode fetchCachePnode(E entity, boolean safe) { + private PNode fetchCachePnode(E entity, boolean safe) { var id = entity.id(); var cachePnode = cache.get(id); if (cachePnode == null) { @@ -273,9 +273,9 @@ public class EntityCache, E extends IEntity> imple var currentTime = TimeUtils.currentTimeMillis(); // key为threadId var updateMap = new HashMap>(); - cache.forEach(new BiConsumer>() { + cache.forEach(new BiConsumer>() { @Override - public void accept(PK pk, PNode pnode) { + public void accept(PK pk, PNode pnode) { var entity = pnode.getEntity(); if (pnode.getModifiedTime() != pnode.getWriteToDbTime()) { pnode.resetTime(currentTime); @@ -303,9 +303,9 @@ public class EntityCache, E extends IEntity> imple public void persistAllBlock() { var currentTime = TimeUtils.currentTimeMillis(); var updateList = new ArrayList(); - cache.forEach(new BiConsumer>() { + cache.forEach(new BiConsumer>() { @Override - public void accept(PK pk, PNode pnode) { + public void accept(PK pk, PNode pnode) { var entity = pnode.getEntity(); if (pnode.getModifiedTime() != pnode.getWriteToDbTime()) { pnode.resetTime(currentTime); @@ -405,13 +405,11 @@ public class EntityCache, E extends IEntity> imple continue; } - // 如果数据库版本号较大,说明缓存的数据不是最新的,直接清除缓存,下次重新加载 - if (dbEntityVersion > entityVersion) { - cache.remove(id); - load(id); - logger.warn("[database:{}] document of entity [id:{}] version [{}] is greater than cache [vs:{}]", entityClass.getSimpleName(), id, dbEntityVersion, entityVersion); - continue; - } + // 数据库版本号较大,说明缓存的数据不是最新的,直接清除缓存,下次重新加载 + cache.remove(id); + load(id); + logger.warn("[database:{}] document of entity [id:{}] version [{}] is greater than cache [vs:{}]", entityClass.getSimpleName(), id, dbEntityVersion, entityVersion); + continue; } } diff --git a/orm/src/main/java/com/zfoo/orm/cache/persister/PNode.java b/orm/src/main/java/com/zfoo/orm/cache/persister/PNode.java index fb65df46..089f0c22 100644 --- a/orm/src/main/java/com/zfoo/orm/cache/persister/PNode.java +++ b/orm/src/main/java/com/zfoo/orm/cache/persister/PNode.java @@ -23,7 +23,7 @@ import com.zfoo.scheduler.util.TimeUtils; * * @author godotg */ -public class PNode> { +public class PNode, E extends IEntity> { // 写入数据库的时间 private volatile long writeToDbTime;