Added a way to disable memcache error ignoring and documented the change. Also changed a bare except to an except on the exception type.
diff --git a/jinja2/bccache.py b/jinja2/bccache.py
index 033ae7a..f022918 100644
--- a/jinja2/bccache.py
+++ b/jinja2/bccache.py
@@ -281,17 +281,25 @@
This bytecode cache does not support clearing of used items in the cache.
The clear method is a no-operation function.
+
+ .. versionadded:: 2.7
+ Added support for ignoring memcache errors through the
+ `ignore_memcache_errors` parameter.
"""
- def __init__(self, client, prefix='jinja2/bytecode/', timeout=None):
+ def __init__(self, client, prefix='jinja2/bytecode/', timeout=None,
+ ignore_memcache_errors=True):
self.client = client
self.prefix = prefix
self.timeout = timeout
+ self.ignore_memcache_errors = ignore_memcache_errors
def load_bytecode(self, bucket):
try:
code = self.client.get(self.prefix + bucket.key)
- except:
+ except Exception:
+ if not self.ignore_memcache_errors:
+ raise
code = None
if code is not None:
bucket.bytecode_from_string(code)
@@ -302,5 +310,6 @@
args += (self.timeout,)
try:
self.client.set(*args)
- except:
- pass
+ except Exception:
+ if not self.ignore_memcache_errors:
+ raise