import { Card, Button, Statistic, Row, Col, Space, Typography, message } from 'antd' import { ClearOutlined, ReloadOutlined, DeleteOutlined } from '@ant-design/icons' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { api } from '@/services/http-client' import type { CacheStats } from '@/types/api' const { Title } = Typography export default function CacheAdmin() { const qc = useQueryClient() const { data: stats, isLoading } = useQuery({ queryKey: ['admin', 'cache-stats'], queryFn: (): Promise => api.get('/admin-api/cache/stats'), refetchInterval: 10_000, }) const flushModule = useMutation({ mutationFn: (module: string) => api.post(`/admin-api/cache/flush/${module}`), onSuccess: (_, mod) => { message.success(`已清除 ${mod} 模块缓存`) qc.invalidateQueries({ queryKey: ['admin', 'cache-stats'] }) }, }) const flushAll = useMutation({ mutationFn: () => api.post('/admin-api/cache/flush-all'), onSuccess: () => { message.success('已清除所有缓存') qc.invalidateQueries({ queryKey: ['admin', 'cache-stats'] }) }, }) const resetStats = useMutation({ mutationFn: () => api.post('/admin-api/cache/reset-stats'), onSuccess: () => qc.invalidateQueries({ queryKey: ['admin', 'cache-stats'] }), }) const modules = [ { key: 'config', label: '配置缓存' }, { key: 'workspace', label: '工作台缓存' }, { key: 'admin', label: 'Admin 缓存' }, { key: 'ai', label: 'AI 路由缓存' }, { key: 'safety', label: '安全词库缓存' }, { key: 'user', label: '用户信息缓存' }, { key: 'kb', label: '知识库缓存' }, ] return (
缓存管理 {modules.map(m => ( ))}
) }