thadeusb/flask-cache — pull request #35 by alanhamlett (2012-10-06 02:28:14+00:00)
Title: handling exceptions when getting keys from internal cache object

When using cache type memcached, the cache interface can raise an exception when getting keys.

For example:

When using pylibmc if the memcached server restarts, the cache interface will raise a _pylibmc.UnknownReadFailure exception. This propagates back up to Flask and causes the request to fail, seen below.

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python2.7/dist-packages/flaskext/cache/__init__.py", line 195, in decorated_function
rv = self.cache.get(cache_key)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/contrib/cache.py", line 325, in get
return self._client.get(key)
_pylibmc.UnknownReadFailure: error 7 from memcached_get(htview//): UNKNOWN READ FAILURE