From f74ada155e2d56fe7732afec2674f2183165dab2 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 6 Jan 2025 13:57:54 +0530 Subject: [PATCH] fix: Don't serve local cache values when it becomes unhealthy --- frappe/utils/redis_wrapper.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frappe/utils/redis_wrapper.py b/frappe/utils/redis_wrapper.py index c0b524c56f..151aeed418 100644 --- a/frappe/utils/redis_wrapper.py +++ b/frappe/utils/redis_wrapper.py @@ -428,13 +428,14 @@ class _ClientCache: frappe.throw("RESP3 is not supported while connecting to Redis.") self.invalidator_thread = self.run_invalidator_thread() self.local_cache: dict[bytes, _ClientCacheValue] = {} + self.cache_healthy = True self._conn_retries = 0 def get_value(self, key): key = self.redis.make_key(key) try: val = self.local_cache[key] - if time.monotonic() < val[1]: + if time.monotonic() < val[1] and self.cache_healthy: return val[0] else: self.local_cache.pop(key, None) # expired @@ -488,9 +489,11 @@ class _ClientCache: self.local_cache.clear() self._conn_retries += 1 if self._conn_retries > 10: + self.cache_healthy = False raise time.sleep(1) else: + self.cache_healthy = False raise def clear_cache(self):