From 24bc6f44a08c4ee5421cf8e4cff77a3cc559533d Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 18 Jun 2026 09:55:04 +0800 Subject: [PATCH] fix(tasks): invalidate session cache after cleaning expired sessions --- src/tasks/session_cleanup.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/tasks/session_cleanup.rs b/src/tasks/session_cleanup.rs index 794e6b6..33a9353 100644 --- a/src/tasks/session_cleanup.rs +++ b/src/tasks/session_cleanup.rs @@ -16,11 +16,17 @@ pub async fn run_cleanup() { match get_conn().await { Ok(client) => { // 删除已过期会话 - if let Err(e) = client + match client .execute("DELETE FROM sessions WHERE expires_at < NOW()", &[]) .await { - tracing::error!("Session cleanup error: {:?}", e); + Ok(_) => { + // 同时清空内存中的会话缓存,避免已失效会话继续命中。 + crate::cache::SESSION_CACHE.invalidate_all(); + } + Err(e) => { + tracing::error!("Session cleanup error: {:?}", e); + } } } Err(e) => {