Last active
December 21, 2015 08:59
-
-
Save jsbueno/6282404 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_page(*dec_args, **dec_kwargs): | |
cache_timeout = dec_args[0] if dec_args else None | |
cache_alias = dec_kwargs.pop('cache', None) | |
key_prefix = dec_kwargs.pop('key_prefix', '') | |
def decorator(func): | |
def wrapped(*func_args, **func_kwargs): | |
request = func_args[0] | |
cache_prefix = u'{}-{}-{}'.format( | |
key_prefix, | |
get_current_site(request).domain, | |
getattr(request, 'is_mobile', False) | |
) | |
deco = django_cache_page(cache_timeout, cache=cache_alias, key_prefix=cache_prefix) | |
return deco(func(*func_args, **func_kwargs)) | |
return wrapped | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment