cache.set() returns None, even in the case of failure
|Reported by:||Owned by:||nobody|
|Component:||Core (Cache system)||Version:||1.3|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The set() method of class BaseMemcachedCache in django.core.cache.backends.memcached does not return the result of the call to self._cache.set(). See this code:
def set(self, key, value, timeout=0, version=None): key = self.make_key(key, version=version) self._cache.set(key, value, self._get_memcache_timeout(timeout))
This means that all set() calls appear to work, even if memcached is down, misconfigured, timing out, etc... It would be much better to have this call return the result of _cache.set(), since then you could tell if your set failed and do something appropriate. This caused a very strange bug in my code, since it appeared that I couldn't read back values from memcached despite the appearance of a successful set().
I have patched my code with the following, simply adding "return" to the above code:
def patched_memcached_set(self, key, value, timeout=0, version=None): key = self.make_key(key, version=version) return self._cache.set(key, value, self._get_memcache_timeout(timeout)) CacheClass.set = patched_memcached_set
Would be nice to have this in the main code line though.