Using Memcached to cache Django views

Django provides a possibility to speed up the request-response cycle by caching the most expensive parts such as database queries or template rendering. The fastest and most reliable caching natively supported by Django is the memory-based cache server, Memcached. In this recipe, you will learn how to use Memcached to cache a view for our viral_videos app that we created in the Using database query expressions recipe earlier in this chapter.

Getting ready

There are several things to do in order to prepare caching for your Django project:

  1. Install Memcached server, as follows:
    $ wget http://memcached.org/files/memcached-1.4.23.tar.gz
    $ tar -zxvf memcached-1.4.23.tar.gz
    $ cd memcached-1.4.23
    $ ./configure && make ...

Get Django: Web Development with Python 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.