wsorenson
wsorenson

Reputation: 5951

Why would Django's cache work with locmem but fail with memcached?

Using Django's cache with locmem (with simple Python classes as values stored in lists/tuples/maps) works perfectly but does not work with memcached.

Only a fraction of the keys (despite ample memory allocated and large timeouts) make their way into memcached, and none of them appear to have any associated value.

When they are retrieved, no value is returned and they are removed from the cache.

Forcing a value of "hi" makes those that appear in the cache retrievable, but does not account for why most of the keys are simply not there.

Questions:

  1. Why do only certain keys end up in memcached and others not, even when all values are set to "hi"?
  2. Is there any way to enable more logging or error reporting? (everything seems to fail silently)
  3. Why do the Python classes serialize correctly to locmem but do not end up in Memcached?

Upvotes: 4

Views: 1221

Answers (2)

wsorenson
wsorenson

Reputation: 5951

Apparently, keys can not have spaces in them:

http://code.djangoproject.com/ticket/6447
http://blog.pos.thum.us/2009/05/22/memcached-keys-cant-have-spaces-in-them/

As soon as I used a key with a space in it, everything became unpredictable.

Upvotes: 3

Alex Martelli
Alex Martelli

Reputation: 881487

To find out what's going on, run memcached -vv 2>/tmp/mc_debug_log (I'm assuming you're on some sort of Unixy system) and run it for a short time -- you'll find detailed information in that logfile when you're done.

Depending on what Python interface to memcached you're using, it may be that only strings are supported as values (as in the StringClient module in cmemcache) or that all pickleable objects are (with the overhead of pickling and unpickling of course), as in the more general Client module in the same cmemcache, GAE's memcache, and python-memcached; if you're only able to use strings as values, presumably you're using an interface of the former type?

Upvotes: 3

Related Questions