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')
Discussion 0
No comments yet. Be the first to start the discussion!
Leave a Comment