def updateObjListByProps(self, props): ''' 根据条件查询数据库,然后把数据同步到缓存 @param props:{} where 条件字典 ''' recordlist = util.GetRecordListByProps(self._name, props) logger.debug('update %s memcahce' % self._name) for record in recordlist: pk = record[self._pk] mm = MMode(self._name + ':%s' % pk, self._pk) if mm.IsEffective() and mm.get('data'): mm.update_mem_only(record) else: mm = MMode(self._name + ':%s' % pk, self._pk, data=record) mm.insert() return True
def getPkListByProps(self, props): ''' 此方法优先查数据库,再对比缓存中是否存在明细记录,如果有该明细记录则用缓存的 适用于初次加载如多条记录,如初次加载道具表信息到缓存时,而getObjList方法需要先取到pklist,再查询一次in操作,性能低 @param props:{} where 条件字典 ''' pklist = [] recordlist = util.GetRecordListByProps(self._name, props) for record in recordlist: pk = record[self._pk] mm = MMode(self._name + ':%s' % pk, self._pk) if not mm.IsEffective() or not mm.get('data'): # mm = MMode(self._name + ':%s' % pk, self._pk, data=record) mm.insert() if self._fk: fk = record[self._fk] self.addFK(fk, pk) pklist.append(pk) return pklist
def getObjListByProps(self, props): ''' 此方法优先查数据库,再对比缓存中是否存在明细记录,如果有该明细记录则用缓存的 适用于初次加载如多条记录,如初次加载道具表信息到缓存时,而getObjList方法需要先取到pklist,再查询一次in操作,性能低 @param props:{} where 条件字典 ''' objlist = [] t0 = time.time() recordlist = util.GetRecordListByProps(self._name, props) logger.debug('recordlist, %.3fs' % (time.time() - t0)) for record in recordlist: pk = record[self._pk] mm = MMode(self._name + ':%s' % pk, self._pk) if mm.IsEffective() and mm.get('data'): objlist.append(mm) continue else: mm = MMode(self._name + ':%s' % pk, self._pk, data=record) mm.insert() objlist.append(mm) logger.debug('finish getObjListByProps, %.3fs' % (time.time() - t0)) return objlist