feat[entity]: add updateNow() method which can update the data in the cache and write it to the database immediately

This commit is contained in:
godotg
2024-01-21 10:54:03 +08:00
parent dbfaff95f0
commit 8417510dbc
2 changed files with 15 additions and 0 deletions
+10
View File
@@ -168,6 +168,16 @@ public class EntityCache<PK extends Comparable<PK>, E extends IEntity<PK>> imple
currentPnode.setModifiedTime(TimeUtils.now() + 100);
}
@Override
public void updateNow(E entity) {
update(entity);
OrmContext.getAccessor().update(entity);
var currentPnode = cache.getIfPresent(entity.id());
var now = TimeUtils.now();
currentPnode.setModifiedTime(now);
currentPnode.setWriteToDbTime(now);
}
@Override
public void invalidate(PK pk) {
// 游戏业务中,操作最频繁的是update,不是insertdeletequery
@@ -32,6 +32,11 @@ public interface IEntityCache<PK extends Comparable<PK>, E extends IEntity<PK>>
*/
void update(E entity);
/**
* 更新缓存中的数据,立刻写入到数据库
*/
void updateNow(E entity);
/**
* 不会删除数据库中的数据,只会删除缓存数据
*