@@ -2,11 +2,11 @@ import { useEffect, useRef } from "react";
22import type { QueryKey } from "@tanstack/query-core" ;
33import { onlineManager , QueryClient } from "@tanstack/react-query" ;
44
5+ import { log } from "./utils/logger" ;
56import { Dehydrate } from "./hydration" ;
7+ import { PlatformOS } from "./platformUtils" ;
68import { SyncMessage } from "./types" ;
79import { useMySocket } from "./useMySocket" ;
8- import { PlatformOS } from "./platformUtils" ;
9- import { log } from "./utils/logger" ;
1010
1111/**
1212 * Query actions that can be performed on a query.
@@ -29,7 +29,9 @@ type QueryActions =
2929 | "ACTION-ONLINE-MANAGER-ONLINE" // Set online manager to online
3030 | "ACTION-ONLINE-MANAGER-OFFLINE" // Set online manager to offline
3131 // Internal action
32- | "success" ; // Internal success action
32+ | "success" // Internal success action
33+ | "ACTION-CLEAR-MUTATION-CACHE" // Clear the mutation cache
34+ | "ACTION-CLEAR-QUERY-CACHE" ; // Clear the query cache
3335
3436/**
3537 * Message structure for query actions between dashboard and devices
@@ -270,6 +272,17 @@ export function useSyncQueriesExternal({
270272 `${ logPrefix } Received query action: ${ action } for query ${ queryHash } ` ,
271273 enableLogs
272274 ) ;
275+ // If action is clear cache do the action here before moving on
276+ if ( action === "ACTION-CLEAR-MUTATION-CACHE" ) {
277+ queryClient . getMutationCache ( ) . clear ( ) ;
278+ log ( `${ logPrefix } Cleared mutation cache` , enableLogs ) ;
279+ return ;
280+ }
281+ if ( action === "ACTION-CLEAR-QUERY-CACHE" ) {
282+ queryClient . getQueryCache ( ) . clear ( ) ;
283+ log ( `${ logPrefix } Cleared query cache` , enableLogs ) ;
284+ return ;
285+ }
273286
274287 const activeQuery = queryClient . getQueryCache ( ) . get ( queryHash ) ;
275288 if ( ! activeQuery ) {
@@ -440,7 +453,15 @@ export function useSyncQueriesExternal({
440453 onlineManagerSubscription ?. off ( ) ;
441454 unsubscribe ( ) ;
442455 } ;
443- } , [ queryClient , socket , deviceName , isConnected , deviceId , enableLogs ] ) ;
456+ } , [
457+ queryClient ,
458+ socket ,
459+ deviceName ,
460+ isConnected ,
461+ deviceId ,
462+ enableLogs ,
463+ logPrefix ,
464+ ] ) ;
444465
445466 return { connect, disconnect, isConnected, socket } ;
446467}
0 commit comments