feat[cache]: get the data in the cache

This commit is contained in:
luca
2024-08-22 17:35:20 +08:00
parent 469cbab443
commit 9a792ec08e
2 changed files with 16 additions and 0 deletions
+9
View File
@@ -176,6 +176,15 @@ public class EntityCache<PK extends Comparable<PK>, E extends IEntity<PK>> imple
return cachePnode;
}
@Override
public E get(PK pk) {
PNode<PK, E> cachePnode = caches.get(pk);
if (cachePnode == null) {
return null;
}
return cachePnode.getEntity();
}
@Override
public void update(E entity) {
var cachePnode = fetchCachePnode(entity, true);
@@ -38,6 +38,13 @@ public interface IEntityCache<PK extends Comparable<PK>, E extends IEntity<PK>>
*/
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);
/**
* 更新缓存中的数据,只更新缓存的时间戳,并通过一定策略写入到数据库
* <p>