26.5.2 Caching Entire Webpages

Why optimize queries or cache template files when we can cache the results of our computations? Django allows us to easily cache the output of views, with templates rendered and middleware already having worked their magic.

Django provides several kinds of caches. For our purposes, we use the local memory cache, which simply keeps computer webpages in memory. When we deploy, we will switch to using a cache for memcache.

It is possible to define multiple different caches, each of which might fulfill a different purpose. In our case, we simply define a single cache called default. The BACKEND key tells the cache what kind of cache it is, while the location gives the cache a unique identifier (used separately from ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.