From 9a7883eb5b8c3b897648f2c300645c38d64bab01 Mon Sep 17 00:00:00 2001 From: dzpt Date: Fri, 10 May 2024 11:51:35 +0700 Subject: [PATCH 1/2] fix jinja template while having cache failure --- src/flask_caching/jinja2ext.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/flask_caching/jinja2ext.py b/src/flask_caching/jinja2ext.py index f4ac10ae..c0eff96b 100644 --- a/src/flask_caching/jinja2ext.py +++ b/src/flask_caching/jinja2ext.py @@ -93,11 +93,22 @@ def _cache(self, timeout, fragment_name, vary_on, caller): #: Delete key if timeout is 'del' if timeout == "del": - cache.delete(key) - return caller() - - rv = cache.get(key) - if rv is None: - rv = caller() - cache.set(key, rv, timeout) - return rv + try: + cache.delete(key) + return caller() + except Exception as e: + if cache.app.debug: + raise e + else: + return caller() + + try: + rv = cache.get(key) + if rv is None: + rv = caller() + cache.set(key, rv, timeout) + except Exception as e: + if cache.app.debug: + raise e + else: + return caller() From c5f4af303481142875b7e953ea2df22a7f5a97f5 Mon Sep 17 00:00:00 2001 From: dzpt Date: Fri, 10 May 2024 12:32:30 +0700 Subject: [PATCH 2/2] fix no return --- src/flask_caching/jinja2ext.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/flask_caching/jinja2ext.py b/src/flask_caching/jinja2ext.py index c0eff96b..43bebb89 100644 --- a/src/flask_caching/jinja2ext.py +++ b/src/flask_caching/jinja2ext.py @@ -107,6 +107,7 @@ def _cache(self, timeout, fragment_name, vary_on, caller): if rv is None: rv = caller() cache.set(key, rv, timeout) + return rv except Exception as e: if cache.app.debug: raise e