mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-21 08:25:28 +00:00
Merge pull request #116 from LucaLq/main
feat[orm]: add an interface to persist the specified cache
This commit is contained in:
+23
-1
@@ -240,12 +240,34 @@ public class EntityCache<PK extends Comparable<PK>, E extends IEntity<PK>> imple
|
||||
}
|
||||
}
|
||||
});
|
||||
persistList(updateList, entityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void persist(PK pk) {
|
||||
var pnode = cache.get(pk);
|
||||
if (pnode == null) {
|
||||
return;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
var entityClass = (Class<E>) entityDef.getClazz();
|
||||
var updateList = new ArrayList<E>();
|
||||
var currentTime = TimeUtils.currentTimeMillis();
|
||||
if (pnode.getModifiedTime() == pnode.getWriteToDbTime()) {
|
||||
return;
|
||||
}
|
||||
var entity = pnode.getEntity();
|
||||
pnode.setWriteToDbTime(currentTime);
|
||||
pnode.setModifiedTime(currentTime);
|
||||
updateList.add(entity);
|
||||
persistList(updateList, entityClass);
|
||||
}
|
||||
|
||||
private void persistList(ArrayList<E> updateList, Class<E> entityClass) {
|
||||
// 执行更新
|
||||
if (updateList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var page = Page.valueOf(1, BATCH_SIZE, updateList.size());
|
||||
var maxPageSize = page.totalPage();
|
||||
|
||||
|
||||
@@ -66,6 +66,13 @@ public interface IEntityCache<PK extends Comparable<PK>, E extends IEntity<PK>>
|
||||
*/
|
||||
void invalidate(PK pk);
|
||||
|
||||
/**
|
||||
* 持久化缓存数据
|
||||
*
|
||||
* @param pk 主键
|
||||
*/
|
||||
void persist(PK pk);
|
||||
|
||||
/**
|
||||
* 持久化所有缓存数据
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user