class BaseHandler(tornado.web.RequestHandler): def __init__(self, *arg, **arg_key_word): super(BaseHandler, self).__init__(*arg, **arg_key_word) self.cache = Cache() self.m = hashlib.md5() self.dbm = DataBaseManager() @tornado.gen.coroutine def response_as_json(self, res): self.set_header("Content-Type", 'application/json; charset="utf-8"') self.write(json.dumps(res)) self.finish() def md5_code(self, string): self.m.update(string) return self.m.hexdigest() def set_cache(self, key, value, time_out): self.cache.set_cache( key=key, value=value, time_out=time_out ) def get_cache(self, key): return self.cache.get_cache(key) def clear_cache(self, key): self.cache.clear_cache(key)