Created
April 13, 2020 13:20
-
-
Save scmmishra/de005a01248d6cda1954a6dc2f3c3a75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cache_result(key, for_user=False, expiry=None): | |
def innerfn(function): | |
def wrapper(*args, **kwargs): | |
_cache = cache() | |
user = None | |
if for_user: | |
user = session.user | |
if kwargs.get("cache"): | |
value = _cache.get_value(key, user=user) | |
if value: | |
return value | |
result = function(*args, **kwargs) | |
_cache.set_value(key, result, user=user, expires_in_sec=expiry) | |
return result | |
return wrapper | |
return innerfn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment