0

I installed them both, but i get a None every time i try to get some key

>>from django.core.cache import cache #no errors
>>cache.set('value1','value2',39) #no errors
>>cache.get('value1') #no errors but no value either

in settings.py i got

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

what is going on wrong? I don't have even the slightest idea what to debug or where to start ...

2
  • 1
    You say you installed them both. Is the memcached server running? Commented Sep 9, 2014 at 12:12
  • bah dum tsssssss! How to start it on my dev machine ? Was not in the docs! Commented Sep 9, 2014 at 12:20

1 Answer 1

1

Are you sure that memcached is actually running, and that it is configured to listen on 127.0.0.1 port 1991? By default memcached listens on port 11211.

django.core.cache.cache plays dumb when memcache fails to store keys, it doesn't raise an exception or return any error.

You can test more directly with memcache like this:

import memcache

for port in (1991, 11211):
    print "Testing memcached on port %d" % port
    mc = memcache.Client(['127.0.0.1:%d' % port])

    if mc.set('value1', 'value2'):
        print "stored key value pair"
        if mc.get('value1') == 'value2':
            print "successfully retrieved value"
            break
        else:
            print "Failed to retrieve value"
    else:
        print "Failed to store key value pair"
Sign up to request clarification or add additional context in comments.

2 Comments

like i said in my other comment, how to start the memcache server on my dev machine? plus how to configure it to the different port?
man memcached? Simply memcached will start it up listening on port 11211 on all interfaces on the local machine. Use memcached -p 1991 to use port 1991. Add the -vv option to see lots of logging.

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.