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?', cleanTitle: 'Are you sure you want to clear the cache?',
cleanDesc: 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', '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': { 'system-notify': {
create: 'Create System Notify', create: 'Create System Notify',
@ -253,7 +254,8 @@ export const i18n: TushanContextProps['i18n'] = {
cleanTitle: '确定要清理缓存么?', cleanTitle: '确定要清理缓存么?',
cleanDesc: cleanDesc:
'生产环境请谨慎操作, 清理缓存可能会导致短时间内数据库压力增加', '生产环境请谨慎操作, 清理缓存可能会导致短时间内数据库压力增加',
cleanBtn: '清理缓存', cleanConfigBtn: '清理配置缓存',
cleanAllBtn: '清理所有缓存',
}, },
'system-notify': { 'system-notify': {
create: '创建系统通知', create: '创建系统通知',

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

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

Loading…
Cancel
Save