"cache_page" decorator accepts "key_prefix" argument.
If "cache_page" will allow "key_prefix" to be callable it will be easier to fine-tune view caching.
For example, it will be easier to have per-user cache or to cache views based on specified GET parameters (there is dedicated #4992 ticket for that).
I've attached patch for that feature.
The sample syntax:
#have 2 static versions of the my_view response for authenticated and anonymous users
def my_key_prefix(request):
if request.GET:
return None #magic value to disable caching
if request.user.is_authenticated():
return 'logged_in'
else:
return 'not_logged_in'
@cache_control(must_revalidate=True)
@cache_page(600, my_key_prefix)
def my_view(request):
....... #something is different for authenticated and anonymous users
#cache my_paginated_view based on "page" parameter in query string
def page_key_prefix(request):
return request.GET.get('page','')
@cache_page(60, page_key_prefix)
def my_paginated_view(request)
.... #page number is passed via 'page' GET parameter and used for pagination