Skip to content

Instantly share code, notes, and snippets.

@victorono
Created December 2, 2013 15:44
Show Gist options
  • Save victorono/7751400 to your computer and use it in GitHub Desktop.
Save victorono/7751400 to your computer and use it in GitHub Desktop.
cache by user django
from django.views.decorators.cache import cache_page
from functools import wraps
from django.utils.decorators import available_attrs
def cache_on_auth(timeout):
def decorator(view_func):
@wraps(view_func, assigned=available_attrs(view_func))
def _wrapped_view(request, *args, **kwargs):
return cache_page(timeout, key_prefix="_auth_%s_" % request.user.is_authenticated())(view_func)(request, *args, **kwargs)
return _wrapped_view
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment