0
所以我重复的代码,我对做很多的GET - 检查响应是否以前缓存并返回,如果它是可用的。重构龙卷风请求处理器
的代码,我想获得工作看起来像这样:
class Handler(web.RequestHandler):
@gen.coroutine
def get_cache(self):
try:
response = yield gen.Task(get_redis)
except:
logging.log()
if response:
self.finish(response)
raise gen.Return()
@gen.coroutine
@asynchronous
def get(self):
self.get_cache()
response = do_sql_get()
self.set_cache(key, response)
self.finish(response)
现在所发生的事情是,它得到的缓存,如果有,但继续运行的代码的其余部分self.get
。这样做对我来说很有意义,但我不知道如何在self.get_cache
方法中调用self.finish
以正确地重构它。