fix(tasks): invalidate session cache after cleaning expired sessions

This commit is contained in:
xfy 2026-06-18 09:55:04 +08:00
parent 518b4e5d64
commit 24bc6f44a0

View File

@ -16,11 +16,17 @@ pub async fn run_cleanup() {
match get_conn().await { match get_conn().await {
Ok(client) => { Ok(client) => {
// 删除已过期会话 // 删除已过期会话
if let Err(e) = client match client
.execute("DELETE FROM sessions WHERE expires_at < NOW()", &[]) .execute("DELETE FROM sessions WHERE expires_at < NOW()", &[])
.await .await
{ {
tracing::error!("Session cleanup error: {:?}", e); Ok(_) => {
// 同时清空内存中的会话缓存,避免已失效会话继续命中。
crate::cache::SESSION_CACHE.invalidate_all();
}
Err(e) => {
tracing::error!("Session cleanup error: {:?}", e);
}
} }
} }
Err(e) => { Err(e) => {