fix(tasks): invalidate session cache after cleaning expired sessions
This commit is contained in:
parent
518b4e5d64
commit
24bc6f44a0
@ -16,13 +16,19 @@ 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
|
||||
{
|
||||
Ok(_) => {
|
||||
// 同时清空内存中的会话缓存,避免已失效会话继续命中。
|
||||
crate::cache::SESSION_CACHE.invalidate_all();
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Session cleanup error: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to get DB connection for cleanup: {:?}", e);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user