Skip to main content

memcached with Django on OS-X

I was developing a Django application for a client. Deployment was on Linux, but I was developing on OS-X. I wanted to do some testing with memcached prior to deployment.

OS-X

memcached comes with OS-X, so that was a good start. Rather than worrying about configuring it to run automatically, I chose to run memcached from the command line, due to my limited needs.

I was testing with the OS-X Apache server, which runs as user _www.

I fired up memcached with the following command line:

$ sudo memcached -l localhost -u _www -vv

Then, to test it, one can telnet into the memcached process and issue commands:

$ telnet localhost 11211

Google telnet and memcached to find examples of interacting with telnet.

Django

Once I verified that memcached was working properly, I configured Django to use it. First:

$ pip install python-memcached

Then I added the following entry to my settings.py file:

CACHES = {
 'default': {
     'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
     'LOCATION': 'localhost:11211',
     'TIMEOUT': 60*5,
     'KEY_PREFIX': '1',
     },
 }