Wednesday 30 October 2013

memcached key limitations

We’ve had observed weird cache behaviour on our website, resulting in old or uncached page modules. Our page consists of different parts which are cached separately and it looked like some of them couldn’t write into our memcached cluster. This problem was not reproducible for a single page module, but appeared randomly on the whole page.

Our default behaviour for cache writing, is to disable the whole cache for the rest of the page if something went wrong. 

Memcached has some constraints about its key and the data saved inside.
Some of them are:

  • Keys are limited to max. 250 characters
  • Serialized data can’t exceed 1 MB 

After adding more and more debug messages, which produced gigabytes of log files, we found another (for us) new, relevant memcached key constraint:

  • You can’t use spaces in your cachename

That’s even specified in the memcached protocol document

But what’s not specified in the document is, that memcached keys can only contain ASCII characters

After fixing these issues our cache hit rate went up again.

No comments:

Post a Comment