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 32092258..75b09d01 100644 --- a/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java +++ b/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java @@ -176,6 +176,15 @@ public class EntityCache, E extends IEntity> imple return cachePnode; } + @Override + public E get(PK pk) { + PNode cachePnode = caches.get(pk); + if (cachePnode == null) { + return null; + } + return cachePnode.getEntity(); + } + @Override public void update(E entity) { var cachePnode = fetchCachePnode(entity, true); diff --git a/orm/src/main/java/com/zfoo/orm/cache/IEntityCache.java b/orm/src/main/java/com/zfoo/orm/cache/IEntityCache.java index 62d820ab..5815d388 100644 --- a/orm/src/main/java/com/zfoo/orm/cache/IEntityCache.java +++ b/orm/src/main/java/com/zfoo/orm/cache/IEntityCache.java @@ -38,6 +38,13 @@ public interface IEntityCache, E extends IEntity> */ E loadOrCreate(PK pk); + /** + * EN: Get the data in the cache or returns null if it does not exist in the cache. + * CN: 获取缓存中的数据,如果缓存中不存在则返回null。 + */ + @Nullable + E get(PK pk); + /** * 更新缓存中的数据,只更新缓存的时间戳,并通过一定策略写入到数据库 *