Does the invoke query function make use of the query cache? #4416
Replies: 2 comments
-
|
No, When you call If you want cache behavior, use the import { useQuery } from "@blitzjs/rpc"
function MyComponent() {
const [data] = useQuery(getDataQuery, { filters })
// This uses React Query under the hood - cached, deduped, refetched on window focus, etc.
}Why the queryKey mismatch? The key mismatch you're seeing ( If you need imperative access to cached data, use the query client directly: import { getQueryClient, getQueryKey } from "@blitzjs/rpc"
const queryClient = getQueryClient()
const key = getQueryKey(getDataQuery, { filters })
// Read from cache without triggering a fetch
const cachedData = queryClient.getQueryData(key)
// Or fetch with cache behavior
const data = await queryClient.fetchQuery({
queryKey: key,
queryFn: () => invoke(getDataQuery, { filters }),
})This way |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
it does not seem to work. Also the queryKey is not what i would expect if you look at what getQueryKey returns.
example:
calling the function a second time does fire a new network request although the i can see the cache data in the ReactQueryDevTools. Also setting the cache manually does not seem to work, because the queryKey does not align. for example getQueryKey(getDataQuery) return /api/rpc/getDataQuery while the ReactQueryDevTools shows that the cache is under: /getDataQuery
Beta Was this translation helpful? Give feedback.
All reactions