Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

MemCachier Django (python) Usage Example

branch: master

MemCachier Django Example

This is an example Django app that uses MemCachier to cache algebraic computations. This example is written with Django 1.5.

You can view a working version of this app here that uses MemCachier on Heroku. Running this app on your local machine in development will work as well, although then you won't be using MemCachier -- you'll be using a local dummy cache. MemCachier is currently only available with various cloud providers.

Setting up MemCachier to work in Django is very easy. You need to make changes to requirements.txt,, and any app code that you want cached. These changes are covered in detail below.


It is best to use the python virtualenv tool to build locally:

$ virtualenv venv --distribute
$ source venv/bin/activate
$ pip install Django psycopg2 dj-database-url django-pylibmc-sasl gunicorn
$ DEVELOPMENT=1 python runserver

Then visit http://localhost:8000 to view the app. Alternatively you can use foreman and gunicorn to run the server locally (after copying dev.env to .env):

$ foreman start

Deploy to Heroku

Run the following commands to deploy the app to Heroku:

$ git clone
$ cd examples-django
$ heroku create
$ heroku addons:add memcachier:dev
$ git push heroku master:master
$ heroku open


MemCachier has been tested with the pylibmc memcache client, but the default client doesn't support SASL authentication. Run the following commands to install the necessary pips:

sudo brew install libmemcached
pip install django-pylibmc-sasl pylibmc

Don't forget to update your requirements.txt file with these new pips. requirements.txt should have the following two lines:


Configure Django to use pylibmc with SASL authentication. You'll also need to setup your environment, because pylibmc expects different environment variables than MemCachier provides. Somewhere in your file you should have the following lines:

os.environ['MEMCACHE_SERVERS'] = os.environ.get('MEMCACHIER_SERVERS', '')
os.environ['MEMCACHE_USERNAME'] = os.environ.get('MEMCACHIER_USERNAME', '')
os.environ['MEMCACHE_PASSWORD'] = os.environ.get('MEMCACHIER_PASSWORD', '')

    'default': {
        'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
        'LOCATION': os.environ.get('MEMCACHIER_SERVERS', ''),
        'TIMEOUT': 500,
        'BINARY': True,

Feel free to change the TIMEOUT setting to match your needs. You can also leave this blank to accept the default value.

Application Code

In your application, use django.core.cache methods to access MemCachier. A description of the low-level caching API can be found here. All the built-in Django caching tools will work, too.

Take a look at memcachier_algebra/ in this repository for an example.

Get involved!

We are happy to receive bug reports, fixes, documentation enhancements, and other improvements.

Please report bugs via the github issue tracker.

Master git repository:

  • git clone git://


This library is BSD-licensed.

Something went wrong with that request. Please try again.