Why not force memcached clients to use the binary protocol instead of the ASCII protocol?
The length check would still be necessary, but spaces (and other arbitrary bytes) would no longer break things.
The length check would still be necessary, but spaces (and other arbitrary bytes) would no longer break things.
Plus, Django actually implements these checks for non-Memcached backends, raising warnings if keys aren't Memcached compatible. This is done because very often in local development users might run the "local memory" cache backend, which is just a Python dict. In this case they probably want to know that what they're doing won't work when it gets to Memcached in production.