From cc67fd9e46f88bf43c8ee12f59816220b8eff674 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 26 Mar 2026 08:58:50 +0000 Subject: [PATCH] refactor: move fs-backed cache under WINDMILL_DIR (#8537) * refactor: move fs-backed cache under WINDMILL_DIR Co-Authored-By: Claude Opus 4.6 (1M context) * feat: add WINDMILL_CACHE_PREFIX env var for per-session cache isolation Co-Authored-By: Claude Opus 4.6 (1M context) * feat: auto-use WEBMUX_BRANCH as cache prefix for session isolation Co-Authored-By: Claude Opus 4.6 (1M context) --------- Co-authored-by: Claude Opus 4.6 (1M context) --- backend/windmill-common/src/cache.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/backend/windmill-common/src/cache.rs b/backend/windmill-common/src/cache.rs index b872b6974e..b3186cc6a2 100644 --- a/backend/windmill-common/src/cache.rs +++ b/backend/windmill-common/src/cache.rs @@ -41,15 +41,14 @@ pub use quick_cache::sync::Cache; #[cfg(not(feature = "scoped_cache"))] lazy_static! { /// Cache directory for windmill server/worker(s). - /// 1. If `XDG_CACHE_HOME` is set, use `"${XDG_CACHE_HOME}/windmill"`. - /// 2. If `HOME` is set, use `"${HOME}/.cache/windmill"`. - /// 3. Otherwise, use `"{std::env::temp_dir()}/windmill/cache"`. + /// Lives under `WINDMILL_DIR` (default `/tmp/windmill`) as `cache_db/`. + /// If `WINDMILL_CACHE_PREFIX` (or `WEBMUX_BRANCH`) is set, uses `cache_db/{prefix}/`. pub static ref CACHE_PATH: PathBuf = { - std::env::var("XDG_CACHE_HOME") - .map(PathBuf::from) - .or_else(|_| std::env::var("HOME").map(|home| PathBuf::from(home).join(".cache"))) - .map(|cache| cache.join("windmill")) - .unwrap_or_else(|_| std::env::temp_dir().join("windmill/cache")) + let base = PathBuf::from(&*crate::worker::WINDMILL_DIR).join("cache_db"); + let prefix = std::env::var("WINDMILL_CACHE_PREFIX") + .or_else(|_| std::env::var("WEBMUX_BRANCH")) + .unwrap_or_default(); + if prefix.is_empty() { base } else { base.join(prefix) } }; }