Enhanced cache_page
decorator for Django views.
Django-cache properly works with Django 1.8, 1.9, 1.10 and 1.11 on Python 2.7, 3.4, 3.5 and 3.6.
- fixed certain amount of bugs (including #15855)
- support of callable
cache_timeout
andkey_prefix
parameters - cache age can be limited by client (min cache age is manageable, default is 0)
from djangocache import cache_page
@cache_page(cache_timeout=600)
def view(request):
pass
If you planning to use cache_page
among with last_modified
and/or etag
the latter must be placed after cache_page
:
from djangocache import cache_page
from django.views.decorators.http import last_modified, etag
def etag_generator(request, *args, **kwargs):
return 'ETag!!'
@cache_page(cache_timeout=600)
@etag(etag_generator)
def view(request, *args, **kwargs):
pass
DJANGOCACHE_MIN_AGE
- used to set minimal age of cache. Default is 0, meaning that client can ask server to skip cache by providing header Cache-Control: max-age=0
.
cache_timeout
. Default issettings.CACHE_MIDDLEWARE_SECONDS
.key_prefix
. Default issettings.CACHE_MIDDLEWARE_KEY_PREFIX
.cache_alias
. Default issettings.CACHE_MIDDLEWARE_ALIAS
, orsettings.DEFAULT_CACHE_ALIAS
if set toNone
.cache_min_age
. Default issettings.DJANGOCACHE_MIN_AGE
.
pip install --upgrade django-cache