def memGetPercentReturns(memkeylist, prefix): EntityDict = {} newMemEntities = {} memCacheEntities = {} memEntities = cachepy.get_multi(memkeylist) missingKeys = meTools.getMissingKeys(memkeylist,memEntities) memCacheEntities = memcache.get_multi(missingKeys) cachepy.set_multi(memCacheEntities) missingKeys = meTools.getMissingKeys(missingKeys,memCacheEntities) memEntities.update(memCacheEntities) if missingKeys: missingKeys = [key.replace(prefix,'') for key in missingKeys] if prefix == 'BTR-': Entities = meSchema.backTestResult.get_by_key_name(missingKeys) elif prefix == 'LAR-': Entities = meSchema.liveAlg.get_by_key_name(missingKeys) for entity in Entities: if entity: memkey = prefix + entity.key().name() pReturn = entity.percentReturn newMemEntities[memkey] = pReturn memEntities[memkey] = pReturn memcache.set_multi(newMemEntities) cachepy.set_multi(newMemEntities) return memEntities