@author: Kevin Chien ''' import inspect from functools import wraps from tornado.gen import coroutine, Return from src.common.logutil import get_logger from src.common.configutil import get_config from src.core.redisutil import get_redis_client from src.common.jsonutil import dict2json, json2dict from src.common.systemutil import get_timestamp ROOT_PREFIX = 'cache' _logger = get_logger(__name__) _config = get_config() def cache(prefix = None, key = None, expires_in = 3600): """ A decorator to cache data. @param prefix: A prefix or namespace in Redis. If the argument is not given, function name will be used. @type prefix: C{string} @param key: The key to be used in Redis. If the argument is not given, all the arguments will be appended to generate the key. @type key: C{string} @param expires_in: How long the cached data expire. If the argument is string, it will be resolved by configutil. Otherwise, it will be used directly. @type expires_in: C{int} """ def _decorator(func): @coroutine
def initialize(self): self._logger = get_logger(self.__class__)
def __init__(self, app_name, app_settings): self._logger = get_logger(self.__class__) self._APP_SETTINGS = app_settings self._SERVC_PREFIX = app_name
def initialize(self): self._logger = get_logger(self.__class__) self._finish = super(BaseHandler, self).finish self._start_time = time.time()