Mike Grouchy

  • Home
  • Posts
Mike Grouchy, February 21 2013

Using Johnny Cache with Heroku and Memcachier

Johnny Cache is a pretty great caching framework for Django. For most apps you can drop Johnny-cache in and depending on your Django project get a good result right out of the box. If this sounds appealing check out the docs for more details.

A recent issue that I have run into is that a deploying a Django App on Heroku with Johnny Cache does not work out of the box with my Memcached service of choice Memcachier.

After some investigation the issue here is that Johnny Cache doesn't support SASL out of the box which is how the authentication for Memcachier works. Memcachier reccomends using django-pylibmc's libmemcached backend to use its app. Of course this isn't compatible with Johnny Cache out of the box either so what do you do?

Create your own SASL compatible backend for Johnny Cache

This is a fairly straightforward problem to solve, we can just inherit from the PyLibMCCachebackend from django-pylibmc and override its _get_memcache_timeout method with the one from Johnny Cache.

Then update your django settings file to point at the new backend you have just created.

Make sure in your CACHES settings dict that you make sure you set BINARY to True and you are off to the races.

Any questions? Feel free to ask in the comments or hit me up on Twitter

Written by

Mike Grouchy

Previous Write less code.
Next Yes, your code does need comments