Caching in Django
Caching reduces database queries and speeds up responses.
Cache Backends
# settings.py
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379/1',
}
}
View Caching
from django.views.decorators.cache import cache_page
@cache_page(60 * 15) # 15 minutes
def my_view(request):
return render(request, 'template.html')
{# Provenance for articles generated from a source document. Rendered
here rather than stored in the body so it stays accurate and cannot
be edited away, and so the sealed draft stays purely generated. #}
Discussion 0
No comments yet. Be the first to start the discussion!
Leave a Comment