mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-20 08:24:16 +00:00
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:
@@ -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,不是insert,delete,query
|
||||
|
||||
@@ -32,6 +32,11 @@ public interface IEntityCache<PK extends Comparable<PK>, E extends IEntity<PK>>
|
||||
*/
|
||||
void update(E entity);
|
||||
|
||||
/**
|
||||
* 更新缓存中的数据,立刻写入到数据库
|
||||
*/
|
||||
void updateNow(E entity);
|
||||
|
||||
/**
|
||||
* 不会删除数据库中的数据,只会删除缓存数据
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user