Created
December 2, 2013 15:44
-
-
Save victorono/7751400 to your computer and use it in GitHub Desktop.
cache by user django
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
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