perf(admin): cache management segmentation

pull/109/head
moonrailgun 2 years ago
parent 5ca5c765b8
commit fba1b261ee

@ -77,7 +77,8 @@ export const i18n: TushanContextProps['i18n'] = {
cleanTitle: 'Are you sure you want to clear the cache?',
cleanDesc:
'Please be cautious in the production environment, clearing the cache may lead to increased pressure on the database in a short period of time',
cleanBtn: 'Clean Cache',
cleanConfigBtn: 'Clean Client Config Cache',
cleanAllBtn: 'Clean All Cache',
},
'system-notify': {
create: 'Create System Notify',
@ -253,7 +254,8 @@ export const i18n: TushanContextProps['i18n'] = {
cleanTitle: '确定要清理缓存么?',
cleanDesc:
'生产环境请谨慎操作, 清理缓存可能会导致短时间内数据库压力增加',
cleanBtn: '清理缓存',
cleanConfigBtn: '清理配置缓存',
cleanAllBtn: '清理所有缓存',
},
'system-notify': {
create: '创建系统通知',

@ -4,6 +4,7 @@ import {
Card,
Message,
Popconfirm,
Space,
useAsyncRequest,
useTranslation,
} from 'tushan';
@ -14,8 +15,10 @@ import { request } from '../request';
*/
export const CacheManager: React.FC = React.memo(() => {
const { t } = useTranslation();
const [, cleanCache] = useAsyncRequest(async () => {
const { data } = await request.post('/cache/clean');
const [, cleanCache] = useAsyncRequest(async (target?: string) => {
const { data } = await request.post('/cache/clean', {
target,
});
if (!data.success) {
Message.error(t('tushan.common.failed') + ':' + data.msg);
@ -27,15 +30,25 @@ export const CacheManager: React.FC = React.memo(() => {
return (
<Card>
<Popconfirm
title={t('custom.cache.cleanTitle')}
content={t('custom.cache.cleanDesc')}
onOk={cleanCache}
>
<Button type="primary" status="danger">
{t('custom.cache.cleanBtn')}
</Button>
</Popconfirm>
<Space direction="vertical">
<Popconfirm
title={t('custom.cache.cleanTitle')}
content={t('custom.cache.cleanDesc')}
onOk={() => cleanCache('config.client')}
>
<Button type="primary">{t('custom.cache.cleanConfigBtn')}</Button>
</Popconfirm>
<Popconfirm
title={t('custom.cache.cleanTitle')}
content={t('custom.cache.cleanDesc')}
onOk={() => cleanCache()}
>
<Button type="primary" status="danger">
{t('custom.cache.cleanAllBtn')}
</Button>
</Popconfirm>
</Space>
</Card>
);
});

@ -16,7 +16,10 @@ router.post('/clean', auth(), async (req, res, next) => {
});
return;
}
await broker.cacher.clean();
const { target = undefined } = req.body;
await broker.cacher.clean(target);
res.json({
success: true,

Loading…
Cancel
Save