Yes Malcolm, thanks for the great and smart answer! You are totally right, this was the reason why I was asking for, I already knew their could be coming up new troubles.
two more questions: ------------------ We don't have troubles with > 255 keys. as we do not have such long keys. But we have that issue: 1) MemcachedKeyCharacterError: Control characters not allowed can't we just turn off caching for these two issues? I think the MD5 solution would work to fix both of them. Why am I the only one who seems to be faced with such issues? I thought millions out there do use memcached as their backend...? Wouldn't be MD5 a great solution to all of us? The guys with small sites, don't have issues with scaling, and the guys with big sites are in the need of a stable memcached backend. Thanks for your help ionic On Thu, 2011-11-10 at 10:02 +0000, Malcolm Box wrote: > On 10 November 2011 08:54, ionic drive <[email protected]> wrote: > Hello django friends, > > Problems: > -------- > 1) MemcachedKeyCharacterError: Control characters not allowed > 2) MemcachedKeyLengthError: Key length is > 250 > > > > The obvious solution is not to generate keys with these properties. > > def _smart_key(self, key): > "Truncate all keys to 250 or less and remove control > characters" > return smart_str(''.join([c for c in key > if ord(c) > 32 and ord(c) ! > = > 127]))[:250] > > > > That looks like a very dangerous, and not very smart key function. > Since you're truncating the key, two keys that should be different > could end up pointing to the same place. That will result in very > difficult to track down bugs. > > > If you really have values that are longer than 255 characters, I'd > suggest running it through a hash function (e.g. MD5) that has a low > probability of collision, and then use that. > > > E.g. if the key was "poll:question:choice:a very long choice here that > takes up 255 characters" I'd turn it into > "poll:question:choice:<MD5 hash of choice text>" > > > Malcolm > > -- > You received this message because you are subscribed to the Google > Groups "Django users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to django-users > [email protected]. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

