By nitin on February 17, 2009
For a project I needed Memcached. But the problem was that I have my development system on WindowsXP.
When I Google I got various links to install Memcached on windows, but there wasn't any link that tell all about Memcached with Django on Windows
So Here we go:
Download memcached 1.2.1 for Win32.
Unzip the binaries in your desired directory (eg. c:\memcached)
Install the service using the command: 'c:\memcached\memcached.exe -d install' from either the command line
Start the server from the Microsoft Management Console or by running the following command: 'c:\memcached\memcached.exe -d start'
Use the server, by default listening to port 11211
Now we have to get something so that python can talk with our memcached server. For this we have various options, but the easiest is python-memcache
Grap latest file from python-memcached-latest.tar.gz
Extract the compressed files in a directory say C:\python-memcache\
Now Run "python setup.py install"
So till this point the installation part is done. Now the question comes how to use it in Django application.
from django.core.cache import cache
def test():
cache_key = 'myID'
result = cache.get(qstr_key)
if result is None:
"""Not Found in Cache"""
data = 'hello'
cache.set(cache_key, data, 86400)
So Basically we have two functions here :
cache.set
cache.get
Go and enjoy the benefit of memcached
- Debugging Django on Windows : Developement Setup
- Why Django ORM Sucks : It takes a hell lot of memory in processing.
- Debugging Django : Best Stuff on Web
- Django ORM : What to do when the memory requirement goes high?
- Implementing Search in Django Site using HayStack and Xapian / Whoosh
Posted in Django, MemCached | Tagged Django, memcache, MemCached, python, win32, windows, windows XP, windowsXP
Hi Nitin,
in the above code the path provided to download the source code gives a package which contains files that need to be compiled. i don’t know how to do that on windows. the package contains readme.txt which guides you to install “libevent” . the third step you mentioned i.e. “c:\memcached\memcached.exe -d install’ ” doesn’t work as there’s is no memcached.exe is there.
Please check the issue and guide me
Thanks saurabh for pointing out the incorrect link…
I have updated the link, you can go ahead with the installation..
Hi Nitin,
Thanks for response, i was trying to setup the memcached envirionment for django application and i successfully installed the server from the link you provided(thanks again), but when i tried to install the client API from the link “ftp://ftp.tummy.com/pub/python-memcached/” i got the latest tar file. when i tried to install the setup.py file from it, the following error occurred :
saurabh.dwivedi@saurabhd /cygdrive/c/bin/python-memcached-1.44
$ python setup.py install
Traceback (most recent call last):
File “setup.py”, line 3, in
from setuptools import setup
ImportError: No module named setuptools
Please can you help me to sort it out …..
Saurabh Dwivedi
I think you need to install http://pypi.python.org/pypi/setuptools
Thanks Nitin, i also serched the same and installed the same. it’s working now, i hope i will able to use it in django also. …:)
Thanks. I spent much time to found data about this.