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 _fresh_token(self):
     qiniu_auth = qiniu.Auth(self.qiniu_token, self.qiniu_secret)
     self.auth = qiniu_auth
     token = qiniu_auth.upload_token(self.qiniu_bucket)
     data_cache.set(self.qiniu_token_key, token, 3580)
     return token
Esempio n. 4
0
def cache_ip_location(ip, location, expire=86400):
    return data_cache.set(ip, location, expire)
Esempio n. 5
0
def cache_lunar_date(date_str, lunar_info):
    return data_cache.set(date_str, lunar_info, 86400)
Esempio n. 6
0
def cache_city_weather(city, weather, expire=1800):
    return data_cache.set(city, weather, expire)