﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7460	cache tag calculates invalid key for memcached	trbs	Jacob	"The cache node from the cache tag calculates it's key from the fragment_name appended by all the vary-on keys in the context joined together by ':'
{{{
 cache_key = u':'.join([self.fragment_name] + \
            [force_unicode(resolve_variable(var, context)) for var in self.vary_on])
}}}

This however can lead to a situation where one uses an object name for one of the vary-on fields which returns a string with a space in it.
For example:

{{{
{% load cache %}
{% cache 7200 sidebar blogname category %}
...
{% endcache %}
}}}

Where category is the data model object for a category. As the same peace of template (DRY) is also used on the frontpage and other pages one cannot be sure that category is a valid object so you cannot use 'category.slug' (which will likely be the default answer to this ticket) Cause this will raise an None has no attribute 'slug' error.

But since category yields a string value there's can be a space in there which memcached does not like for it's keys.
{{{
[ERROR@1213562932.703199] mcm_validate_key_func():3443: memcache(4) protocol error: isspace(3) returned true for character in key
}}}

In this example the key will become: ""sidebar:myweblog:Some Category"" where the space between some and category will be the problem yielding the memcache error above.

The attached patch modifies the cache templatetag to guaranty that the key does not contain spaces. This seemed to be the best place, as the cache tag is used from the a template and not from code.

I've also thought about maybe handling this in the cache backend for memcached, which at first hand seemed another valid place as that also converts any non-ascii key to ascii ignoring all other characters. But i don't like a backend to start changing things for the user which can lead to unexpected results. 

(Granted this already is the case in the memcached backend because of .encode('ascii', 'ignore') which will break an ignorant users caching when he using non-ascii characters in the key string. For example, when using localized texts as key strings. But that's another matter :) )

"		closed	Core (Cache system)	dev		fixed	memcached, space, problem, with, in, key		Accepted	1	0	0	1	0	0
