Spaces:
Sleeping
Sleeping
| import { QueryClient } from '@tanstack/react-query'; | |
| // グローバルなQueryClientインスタンスを保持 | |
| let globalQueryClient: QueryClient | null = null; | |
| export function setQueryClient(client: QueryClient) { | |
| globalQueryClient = client; | |
| } | |
| export function getQueryClient(): QueryClient { | |
| if (!globalQueryClient) { | |
| throw new Error('QueryClient has not been initialized'); | |
| } | |
| return globalQueryClient; | |
| } | |
| // Proposal関連のクエリを無効化する関数 | |
| export async function invalidateProposalQueries(): Promise<void> { | |
| console.log('[QueryClient] Invalidating all proposal queries...'); | |
| const queryClient = getQueryClient(); | |
| // proposal関連のすべてのキャッシュを無効化 | |
| await queryClient.invalidateQueries({ | |
| predicate: (query) => { | |
| const key = query.queryKey[0]; | |
| const isProposalQuery = ['themeByMoment', 'proposalFv', 'proposalCn', 'proposalPrediction', 'proposalIntent'].includes(key as string); | |
| if (isProposalQuery) { | |
| console.log(`[QueryClient] Invalidating query: ${key}`); | |
| } | |
| return isProposalQuery; | |
| }, | |
| }); | |
| // キャッシュからも削除 | |
| queryClient.removeQueries({ | |
| predicate: (query) => { | |
| const key = query.queryKey[0]; | |
| return ['themeByMoment', 'proposalFv', 'proposalCn', 'proposalPrediction', 'proposalIntent'].includes(key as string); | |
| }, | |
| }); | |
| console.log('[QueryClient] Proposal queries invalidated and removed from cache'); | |
| } | |
| export { globalQueryClient as queryClient }; | |