Skip to content

Instantly share code, notes, and snippets.

@jsbueno
Last active December 21, 2015 08:59
Show Gist options
  • Save jsbueno/6282404 to your computer and use it in GitHub Desktop.
Save jsbueno/6282404 to your computer and use it in GitHub Desktop.
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