freyja 将引入“分组”概念进一步提高维护缓存时的效率
目前的freyja在维护缓存的时候是将表分为多个字段,每个字段负责维护与字段有关的缓存。
当字段update的时候去检测是否需要缓存失效。
经过我对这些数据的分析,引入分组概念能加快维护缓存的效率。
例如,大部分数据都是围绕用户产生的,User、Hero、Building 他们都是一对多关系,在这些表当中,大部分查询都是限于当前用户的数据查询。那么按userId分组将大大的减少检索的内容,从而提高维护缓存的效率。
当然其他的表也可以根据自己的情况分组/不分组。
另外也许还会采用single注解减少update操作,被single注解的表明当前字段不会出现在联表查询范围内。那么这个字段的update操作就不需要序列化到数据库,在系统关闭/缓存过期的时候update一次就足够了
[Freyja] [SQL] update t_hero set STATUS = ?,holdNumber = ? where ID = ? [args] 1 100 6769
[Freyja]
14:14:26,718 - 扫描cache: SELECT * FROM t_hero AS h WHERE h.user_id = ? AND STATUS >= 0#@7272
14:14:26,718 - 扫描cache: SELECT * FROM t_hero WHERE user_id = ? AND CITY_ID = 0 AND STATUS IN (0, 1)#@7273
14:14:26,718 - 移除 cache:from Hero where userId = ? and cityId = 0 and status in (0,1)#null#null#0#@7273
14:14:26,718 - 移除 cache:SELECT * FROM t_hero WHERE user_id = ? AND CITY_ID = 0 AND STATUS IN (0, 1)#@7273
14:14:26,718 - 扫描cache: SELECT * FROM t_hero WHERE user_id = ? AND CITY_ID = 0 AND STATUS IN (0, 1)#@7272
14:14:26,718 - 扫描cache: SELECT * FROM t_hero AS t WHERE t.user_id = 7273 AND STATUS >= 0#
14:14:26,718 - 移除 cache:select t.id as id,t.name as name,t.level as level,t.legendFlag as legendFlag,t.status as status,t.cityId as cityId,t.holdNumber as holdNumber,t.battleAtTime as battleAtTime from Hero t where t.userId = 7273 and status >=0#null#null#1#
14:14:26,718 - 扫描cache: SELECT * FROM t_hero AS t WHERE t.user_id = 7272 AND STATUS >= 0#
14:14:26,718 - 扫描cache: SELECT * FROM t_hero AS h WHERE h.user_id = ? AND STATUS >= 0#@7273
14:14:26,718 - 移除 cache:select h.id as id,h.name as name,h.status as status from Hero h where h.userId = ? and status >= 0#null#null#1#@7273
14:14:26,718 - 扫描cache: SELECT * FROM t_hero WHERE user_id = ? AND CITY_ID = 0 AND STATUS IN (0, 1)#@7272
14:14:26,718 - 扫描cache: SELECT * FROM t_hero AS h WHERE h.user_id = ? AND STATUS >= 0#@7272
14:14:26,718 - 扫描cache: SELECT * FROM t_hero WHERE user_id = ? AND CITY_ID = 0 AND STATUS IN (0, 1)#@7272
14:14:26,718 - 扫描cache: SELECT * FROM t_hero AS t WHERE t.user_id = 7273 AND STATUS >= 0#
14:14:26,718 - 移除 cache:select t.id as id,t.name as name,t.level as level,t.legendFlag as legendFlag,t.status as status,t.cityId as cityId,t.holdNumber as holdNumber,t.battleAtTime as battleAtTime from Hero t where t.userId = 7273 and status >=0#null#null#1#
14:14:26,718 - 扫描cache: SELECT * FROM t_hero AS t WHERE t.user_id = 7272 AND STATUS >= 0#
14:14:26,718 - 扫描cache: SELECT * FROM t_hero AS h WHERE h.user_id = ? AND STATUS >= 0#@7273
14:14:26,718 - 移除 cache:select h.id as id,h.name as name,h.status as status from Hero h where h.userId = ? and status >= 0#null#null#1#@7273
一个用户的hero更新,按照现在的需要扫描所有用户的hero,通过分组可以将扫描内容减少到之前的 1/n n为用户数。
7272 和7273 为2个用户的ID