Esempio n. 1
0
 def wrapper(*args, **kwargs):
     from weixin.cache import data_cache
     key = ''
     for arg in args:
         if isinstance(arg, basestring):
             key = arg
     if not key:
         for arg, arg_value in kwargs.items():
             if isinstance(arg_value, basestring):
                 key = arg_value
                 break
     if not key:
         if len(args) > 0:
             key = json.dumps(args[0])
         elif len(kwargs) > 0:
             key = json.dumps(kwargs.values()[0])
         else:
             key = uuid.uuid4().hex
     key += key_info
     key = hashlib.md5(key).hexdigest()
     cache_data = data_cache.get(key)
     if cache_data:
         data = json.loads(cache_data)
         # data = unicode2utf(data)
         return data
     data = func(*args, **kwargs)
     if data:
         data_cache.set(key, json.dumps(data, ensure_ascii=False),
                        expire_time)
     return data
Esempio n. 2
0
 def wrapper(params):
     key = params
     if isinstance(params, dict):
         key = json.dumps(params)
     elif isinstance(params, list):
         key = json.dumps(params)
     elif isinstance(params, unicode):
         key = params.encode("utf-8")
     key = hashlib.md5(key).hexdigest()
     cache_data = data_cache.get(key)
     if cache_data:
         data = json.loads(cache_data)
         data = unicode2utf(data)
         return data
     data = func(params)
     data_cache.set(key, json.dumps(data, ensure_ascii=False), 3600)
     return data
Esempio n. 3
0
 def qiniu_access_token(self):
     token = data_cache.get(self.qiniu_token_key)
     if not token:
         token = self._fresh_token()
     return token
Esempio n. 4
0
def get_lunar_date(date_str):
    return data_cache.get(date_str)
Esempio n. 5
0
def get_city_weather(city):
    return data_cache.get(city)
Esempio n. 6
0
def get_ip_location(ip):
    return data_cache.get(ip)