Skip to content

Commit

Permalink
perf(admin): cache management segmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Jul 15, 2023
1 parent 5ca5c76 commit fba1b26
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
6 changes: 4 additions & 2 deletions server/admin/src/client/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -253,7 +254,8 @@ export const i18n: TushanContextProps['i18n'] = {
cleanTitle: '确定要清理缓存么?',
cleanDesc:
'生产环境请谨慎操作, 清理缓存可能会导致短时间内数据库压力增加',
cleanBtn: '清理缓存',
cleanConfigBtn: '清理配置缓存',
cleanAllBtn: '清理所有缓存',
},
'system-notify': {
create: '创建系统通知',
Expand Down
35 changes: 24 additions & 11 deletions server/admin/src/client/routes/cache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Card,
Message,
Popconfirm,
Space,
useAsyncRequest,
useTranslation,
} from 'tushan';
Expand All @@ -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);
Expand All @@ -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>
);
});
Expand Down
5 changes: 4 additions & 1 deletion server/admin/src/server/router/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fba1b26

Please sign in to comment.