MemCachier in Heroku just got easier in Django

Randall Degges just added MemCachier to his Django automatic memcache module, which makes setting up MemCachier in Django as easy as installing a module. We’ll show you how.

All you need to do is:

$ heroku addons:add memcachier:25
$ pip install django-heroku-memcacheify

And add the following to

from memcacheify import memcacheify
import os
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', '')
CACHES = memcacheify()

Then, to test if it’s working, run:

$ heroku run python shell
Running python shell attached to terminal... up, run.1
Python 2.7.2 (default, Oct 31 2011, 16:22:04)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.core.cache import cache
>>> cache.set('memcache', 'ify!')
>>> cache.get('memcache')

Checkout django-heroku-memcacheify on github for more information. Thanks, Randall!

UPDATE: these instructions will be even easier once this pull request is merged. Once it’s merged, you won’t need to muck with environment variables at all.