Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check the content of a Django cache with Python memcached?

Tools version:

  • Python 2.6.5
  • Django 1.3.1
  • memcached 1.4.10
  • python-memcached 1.48

Memcached is currently running:

$ ps -ef | grep memcache
nobody    2993     1  0 16:46 ?        00:00:00 /usr/bin/memcached -m 64 -p 11211 -u nobody -l 127.0.0.1

I'm using memcached and python memcached with my Django proj and I've set it like the following in settings.py:

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

I've set the cache in the code:

from django.core.cache import cache
cache.set('countries', ['Canada', 'US'])

I then open a Django shell to inspect the content of the cache:

>>> from django.core.cache import cache
>>> 'countries' in cache
True
>>> import memcache
>>> mc = memcache.Client(['127.0.0.1:11211'], debug=1)
>>> mc.get('countries')
>>> 

When I use Django's cache, countries key exists. However, when I use Python's memcache, I don't get anything for countries. What am I doing wrong above?

like image 819
Thierry Lam Avatar asked Dec 14 '11 22:12

Thierry Lam


1 Answers

Django prefixes cache keys with a colon. You can inspect memcached like so if this doesn't help.

like image 200
tback Avatar answered Oct 06 '22 00:10

tback