0PricingLogin
Django Academy · Lesson

Per-View and Per-Site Caching

Cache whole pages with decorators.

Cache the Whole Page

Sometimes a full page is expensive to build. Django can store the entire rendered response and replay it for the next visitor.

The cache_page Decorator

Wrap a view in cache_page and Django caches its full output for the number of seconds you pass in.

from django.views.decorators.cache import cache_page

@cache_page(60 * 15)
def article_list(request):
    ...

All lessons in this course

  1. Cache Backends and Redis
  2. Per-View and Per-Site Caching
  3. Template Fragment Caching
  4. Low-Level cache API and Invalidation
← Back to Django Academy