def wrapper(*args, **kwargs): key = "%s::%s" % (settings.REDIS_KEYPREFIX, key_prefix) if util.redis_cache_is_enabled(): output = sentinel.slave.get(key) if output: return pickle.loads(output) output = f(*args, **kwargs) sentinel.master.setex(key, timeout, pickle.dumps(output)) return output output = f(*args, **kwargs) return output
def delete_cached(key): """ Delete a cached value from the cache. Returns True if success or no cache is enabled """ if util.redis_cache_is_enabled(): key = "%s::%s" % (settings.REDIS_KEYPREFIX, key) return bool(sentinel.master.delete(key)) return True
def wrapper(*args, **kwargs): 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) if util.redis_cache_is_enabled(): output = sentinel.slave.get(key) if output: return pickle.loads(output) output = f(*args, **kwargs) sentinel.master.setex(key, timeout, pickle.dumps(output)) return output output = f(*args, **kwargs) return output
def delete_memoized(function, *args, **kwargs): """ Delete a memoized value from the cache. Returns True if success or no cache is enabled """ if util.redis_cache_is_enabled(): key = "%s:%s_args:" % (settings.REDIS_KEYPREFIX, function.__name__) if args or kwargs: key_to_hash = get_key_to_hash(*args, **kwargs) key = get_hash_key(key, key_to_hash) return bool(sentinel.master.delete(key)) keys_to_delete = sentinel.slave.keys(pattern=key + '*') if not keys_to_delete: return False return bool(sentinel.master.delete(*keys_to_delete)) return True