From 46dbb2f0cd25ba0b588635e9d17cf17b358c0bb2 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 3 Jan 2025 11:38:53 +0530 Subject: [PATCH] perf: Evict site cache only on `frappe.clear_cache()` (#29033) For doctype/user specific cache eviction, no need to remove site_cache. Rationale: - Site cache is worker specific, so this eviction doesn't help much. - Anything that might need to be evicted from site cache should be manually cleared or use a TTL. Maybe we can just replace all of site_cache usage with https://github.com/frappe/frappe/pull/28992 once it's stable. --- frappe/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index 9444f3a518..7e958e57fd 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -968,7 +968,9 @@ def clear_cache(user: str | None = None, doctype: str | None = None): for fn in get_hooks("clear_cache"): get_attr(fn)() - frappe.utils.caching._SITE_CACHE.clear() + if (not doctype and not user) or doctype == "DocType": + frappe.utils.caching._SITE_CACHE.clear() + local.role_permissions = {} if hasattr(local, "request_cache"): local.request_cache.clear()