Issue #64 new

unable to detect when memcached isn't running

David Kavanagh
created an issue

I've configured dogpile.cache to use memcached and the python-memcached package. I need to be able to detect when there is a failure to communicate to the memcached server. In python-memcached'd memcached.py file, the _set(..) method around line 814, a 0 is returned if the server is down. The set method returns a non-zero value on success. In the dogpile.cache.backends.memcached.py file around line 159, the set(..) method does nothing with the return value, as does the dogpile.cache.region.py file in the set(..) method. That makes it impossible to know and deal with a memcached set failure. I'd be happy to submit a patch, but wanted some feedback first. Perhaps raising a DogpileCacheException from the backend would be better.

Comments (8)

  1. David Kavanagh reporter

    I've forked the projected and setup a BackendCacheException(DogpileCacheException) class. I raise that in the backends.memcached.py for set and delete when a zero is returned. This works well for the case I had in mind. I find that it also causes the @cache_on_arguments() decorator to throw an exception if the cache isn't there, so it isn't as hands-off as before. I'm toying with having the decorator swallow the exception so that it is less intrusive. However, it could be nice to have a way to tell if the cache isn't functioning... open to ideas.

  2. Mike Bayer repo owner

    pylibmc should be raising an error for any cache not available case, so this wouldn't change much. I'm not understanding why @cache_on_arguments throwing an exception is a bad thing, assuming we mean when the decorated function is actually called. for seamless transition I'd support the python-memcached backend raising if a config flag is set.

  3. David Kavanagh reporter

    got back to looking at this. Build pylibmc and get the ConnectionError when memcached is stopped. It looks like the decorated create method fails fast (probably when checking for the key in the cache), so if I re-structure my code a little, I can fall-back to simply calling the create method and returning the value. I'll have to have the decorated method call another method.. layers and layers!

  4. Log in to comment