[Answer]-Caching using Memcached and python-memcache

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"
👤mhawke

Leave a comment