mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-15 18:16:09 +00:00
Merge pull request #116 from LucaLq/main
feat[orm]: add an interface to persist the specified cache
This commit is contained in:
2 files changed
+30
-1
No files matched your search
+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()) {
|
if (updateList.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var page = Page.valueOf(1, BATCH_SIZE, updateList.size());
|
var page = Page.valueOf(1, BATCH_SIZE, updateList.size());
|
||||||
var maxPageSize = page.totalPage();
|
var maxPageSize = page.totalPage();
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,13 @@ public interface IEntityCache<PK extends Comparable<PK>, E extends IEntity<PK>>
|
|||||||
*/
|
*/
|
||||||
void invalidate(PK pk);
|
void invalidate(PK pk);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 持久化缓存数据
|
||||||
|
*
|
||||||
|
* @param pk 主键
|
||||||
|
*/
|
||||||
|
void persist(PK pk);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 持久化所有缓存数据
|
* 持久化所有缓存数据
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in new issue
Block a user