Skip to content

Commit bc6e908

Browse files
committed
perf: 退出系统时自动清除当前用户的缓存信息
1 parent affd6e8 commit bc6e908

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

dash-fastapi-frontend/callbacks/app_c.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from dash.dependencies import Input, Output, State
44
from flask import session
55
from server import app
6+
from utils.cache_util import CacheManager
67

78

89
# api拦截器——退出登录二次确认
@@ -17,6 +18,7 @@
1718
def redirect_page(okCounts):
1819
if okCounts:
1920
session.clear()
21+
CacheManager.clear()
2022

2123
return [dcc.Location(pathname='/login', id='index-redirect'), None]
2224

dash-fastapi-frontend/callbacks/layout_c/head_c.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from flask import session
66
from api.login import LoginApi
77
from server import app
8+
from utils.cache_util import CacheManager
89

910

1011
# 页首右侧个人中心选项卡回调
@@ -58,6 +59,7 @@ def logout_confirm(okCounts):
5859
result = LoginApi.logout()
5960
if result['code'] == 200:
6061
session.clear()
62+
CacheManager.clear()
6163

6264
return [dcc.Location(pathname='/login', id='index-redirect'), None]
6365

dash-fastapi-frontend/utils/cache_util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ def delete(cls, target_key: str):
6161
cache.pop(target_key, None)
6262
cache_manager.insert(session.get('Authorization'), cache)
6363

64+
@classmethod
65+
def clear(cls):
66+
"""
67+
清空缓存值
68+
69+
:return:
70+
"""
71+
cache = cache_manager.get(session.get('Authorization'))
72+
if cache:
73+
del cache_manager[session.get('Authorization')]
74+
6475

6576
class TTLCacheManager:
6677
"""

0 commit comments

Comments
 (0)