4

I am trying to use Memcache in my Django app, but it seems that something in my configuration is missing. Any help would be appreciated, Thank you!

$ python manage.py shell
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.cache import cache
>>> cache.set('my_key', 'hello, world!', 30)
>>> print cache.get('my_key')
None
>>> 

Settings.py

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211', 
    }
}

APIs installed:

$ pypm install python-memcached
$ brew install memcached
$ brew install libmemcached
7
  • 1
    Did you start memcached? Commented Aug 22, 2013 at 15:05
  • How do I do that?, I thought I just had to add it on the Django's settings Commented Aug 22, 2013 at 15:06
  • 'LOCATION': '127.0.0.1:8000' this is supposed to be location of memcached, not Django Commented Aug 22, 2013 at 15:06
  • @vartec I already try it with 11211, without any clue' Commented Aug 22, 2013 at 15:12
  • 1
    telnet localhost 11211 if you get Connection refused your memcached is not running. If you get telnet prompt, type stats. You should get bunch of memcached's stats, if you don't your memcache isn't configured properly Commented Aug 22, 2013 at 15:23

2 Answers 2

7

I think I had some issues in my configuration, so I just installed Memcache again using MacPorts

$ sudo port install memcached 

and then I ran Memcache, and it works

$ memcached -vv

These instructions have been tested on Mac OS X 10.7.5 (Lion)

For more information visit this website

Sign up to request clarification or add additional context in comments.

Comments

4

Thanks, just want to add that it worked for me on ubuntu machine too...

to install in ubuntu :

$sudo apt-get install memcached

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.