Django and Memcached: Set Value Not Working

I had a strange memcached bug while using Django. Sometime cache.set(key, value) would save the value. Other times it would not. No warnings or errors. Just not saved.

It turns out the item I was trying to save was near the item size limit of memcached. The default is 1 MB (see the -I flag). Sometimes the item would be less than the max and set would work. Other times it would exceed the limit and set would just stop working.

The man page recommends not exceeding the default. So I solved the problem by saving the item in two parts.

I should also mention that Django file-based cache is pretty easy to use and does not have this limitation. Since all my Django sites run on SSD drives, file-based cache is almost as fast as memcached.