From 33d07ac49a01a5b4222e3e073c230805b45eeac4 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 25 Mar 2024 12:30:58 +0100 Subject: [PATCH] fix: get_or_set_cache - Use Falsy cached values except None If `is_frappe_db` returned False, the value was cached but always re-ran the function anyway making repeated unnecessary Database connections and Error Logs to be created on execution of each query. --- insights/cache_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/insights/cache_utils.py b/insights/cache_utils.py index a5851a381..37e8b41b9 100644 --- a/insights/cache_utils.py +++ b/insights/cache_utils.py @@ -20,7 +20,7 @@ def make_digest(*args): def get_or_set_cache(key, func, force=False, expiry=EXPIRY): key = f"insights|{key}" cached_value = frappe.cache().get_value(key) - if cached_value and not force: + if cached_value is not None and not force: return cached_value value = func()