Installing Memcached for Django Application on Windows XP

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.4 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

    10 Responses

    1. saurabh dwivedi #

      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

      Reply
      • nitin #

        Thanks saurabh for pointing out the incorrect link…

        I have updated the link, you can go ahead with the installation..

        Reply
    2. saurabh dwivedi #

      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

      Reply
    3. saurabh dwivedi #

      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. …:)

      Reply
    4. cheng #

      Thanks. I spent much time to found data about this.

      Reply
    5. Aditya #

      Very nice and concise steps!! Cheers man!

      Reply
      • Aditya #

        Hey is there no configuration required for ‘Settings.py’ file for memcache? Let me know..

        Reply

    Leave a Reply