Skip to content

Instantly share code, notes, and snippets.

@jsbueno

jsbueno/cache.py

Last active Dec 21, 2015
Embed
What would you like to do?
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