[Fixed]-How do I check the content of a Django cache with Python memcached?


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



You can use memcached_stats from:

(I used pylibmc for the cache, but I think this should be the same is you use python-memcached)

import pylibmc

from memcached_stats import MemcachedStats
mem = MemcachedStats() # connecting to localhost at default memcached port

# print out all your keys

# say for example key[0] is 'countries', then to get the value just do
key = mem.keys()[0]

import memcache
mc = memcache.Client([''], debug=1)
value = mc.get (key)

There is also a command line interface to memcaced_stats:
python -m memcached_stats

Have a look at the github repo as the README is very clear.


The following script dumps all the keys of a memcached server. It’s tested with Ubuntu 12.04 and a localhost memcached, so your milage may vary.

#!/usr/bin/env bash

echo 'stats items'  \
| nc localhost 11211  \
| grep -oe ':[0-9]*:'  \
| grep -oe '[0-9]*'  \
| sort  \
| uniq  \
| xargs -L1 -I{} bash -c 'echo "stats cachedump {} 1000" | nc localhost 11211'

What it does, it goes through all the cache slabs and print 1000 keys of each.

Leave a comment