Beispiel #1
0
 def wrapper(*args, **kwargs):
     if os.environ.get('PYBOSSA_REDIS_CACHE_DISABLED') is None:
         key = "%s::%s" % (settings.REDIS_KEYPREFIX, key_prefix)
         output = redis_slave.get(key)
         if output:
             return pickle.loads(output)
         else:
             output = f(*args, **kwargs)
             redis_master.setex(key, timeout, pickle.dumps(output))
             return output
     else:
         return f(*args, **kwargs)
Beispiel #2
0
 def wrapper(*args, **kwargs):
     if os.environ.get('PYBOSSA_REDIS_CACHE_DISABLED') is None:  # pragma: no cover
         key = "%s::%s" % (settings.REDIS_KEYPREFIX, key_prefix)
         output = redis_slave.get(key)
         if output:
             return pickle.loads(output)
         else:
             output = f(*args, **kwargs)
             redis_master.setex(key, timeout, pickle.dumps(output))
             return output
     else:
         return f(*args, **kwargs)
Beispiel #3
0
 def wrapper(*args, **kwargs):
     if os.environ.get('PYBOSSA_REDIS_CACHE_DISABLED') is None:  # pragma: no cover
         key = "%s:%s_args:" % (settings.REDIS_KEYPREFIX, f.__name__)
         key_to_hash = get_key_to_hash(*args, **kwargs)
         key = get_hash_key(key, key_to_hash)
         print "Memoize %s" % key
         output = redis_slave.get(key)
         if output:
             return pickle.loads(output)
         else:
             output = f(*args, **kwargs)
             redis_master.setex(key, timeout, pickle.dumps(output))
             return output
     else:
         return f(*args, **kwargs)
Beispiel #4
0
 def wrapper(*args, **kwargs):
     if os.environ.get('PYBOSSA_REDIS_CACHE_DISABLED') is None:
         key = "%s:%s_args:" % (settings.REDIS_KEYPREFIX, f.__name__)
         key_to_hash = ""
         for i in args:
             key_to_hash += ":%s" % i
         key_to_hash = key_to_hash.encode('utf-8')
         key = key + ":" + hashlib.md5(key_to_hash).hexdigest()
         #key += "_kwargs"
         #for i in frozenset(kwargs.items()):
         #    key += ":%s" % i
         output = redis_slave.get(key)
         if output:
             return pickle.loads(output)
         else:
             output = f(*args, **kwargs)
             redis_master.setex(key, timeout, pickle.dumps(output))
             return output
     else:
         return f(*args, **kwargs)
Beispiel #5
0
 def wrapper(*args, **kwargs):
     if os.environ.get('PYBOSSA_REDIS_CACHE_DISABLED') is None:  # pragma: no cover
         key = "%s:%s_args:" % (settings.REDIS_KEYPREFIX, f.__name__)
         key_to_hash = ""
         for i in args:
             key_to_hash += ":%s" % i
         key_to_hash = key_to_hash.encode('utf-8')
         key = key + ":" + hashlib.md5(key_to_hash).hexdigest()
         #key += "_kwargs"
         #for i in frozenset(kwargs.items()):
         #    key += ":%s" % i
         output = redis_slave.get(key)
         if output:
             return pickle.loads(output)
         else:
             output = f(*args, **kwargs)
             redis_master.setex(key, timeout, pickle.dumps(output))
             return output
     else:
         return f(*args, **kwargs)