def cached(key='view{path}'):
""" Sets up a function to have cached results """
def decorator(func):
""" Gets a cached value or calculates one """
@wraps(func)
def decorated_function(*args, **kwargs):
ckey = cache_key(key, *args, **kwargs)
value = cache.get(ckey)
if value is not None:
return value
print("DB HIT: \"{}\"".format(ckey))
value = func(*args, **kwargs)
cache.set(ckey, value)
return value
return decorated_function
return decorator
评论列表
文章目录