worthy-roseW
Refine7mo ago
11 replies
worthy-rose

TQ cache isn't working in existing project

Hi, I'm new here and enjoying Refine so far, but there's an issue with Tanstack Query not caching. This is in an existing project that also uses Apollo, not sure if that's a conflict.

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      retry: 1,
      refetchOnWindowFocus: false,
      staleTime: 5 * 60 * 1000, // 5 minutes
      gcTime: 10 * 60 * 1000, // 10 minutes
      refetchOnMount: false,
      refetchOnReconnect: false
    }
  }
})

    <QueryClientProvider client={queryClient}>
      <DevtoolsProvider>
        <Refine
          dataProvider={{
            default: buyingProductDataProvider,
            buyingProduct: buyingProductDataProvider
          }}
          options={{
            // ...tried this too, but removed it...
            reactQuery: {
              clientConfig: {
                defaultOptions: {
                  queries: {
                    staleTime: 5 * 60 * 1000, // 5 minutes
                    cacheTime: 10 * 60 * 1000, // 10 minutes
                    refetchOnWindowFocus: false
                  }
                }

// in the useList hook, which works, I'm passing:
    queryOptions: {
      queryKey: ['buyingProduct', 'list']
    }


I've implemented a data provider with
getList
and have made a useList call, but logging queryClient.getQueryCache().getAll().length returns 0 repeatedly.

I tried and Tanstack's useQuery does populate the cache correctly, but I'd like to get Refine working.
My goal is to see if I can have getList auto-trigger after update, which would reduce a tone of manual refetch code.

Am I missing something in my setup? Thanks in advance,
- MG
Was this page helpful?