How to avoid duplicate API requests from both Server and Client sides using the @tanstack/vue-query package in Vue? #8738
-
I recently took over a project where the frontend uses the @tanstack/vue-query package to send API requests to the backend. How can I avoid duplicate API requests from both the Server and Client sides? I asked Copilot, and the answer provided was as follows: Vue Query's caching mechanism can effectively avoid duplicate API calls from the server and client sides through the following aspects:
However, according to the official caching guide (https://tanstack.com/query/latest/docs/framework/vue/guides/caching), it seems that only setting the staleTime prevents duplicate API requests within the specified time range. So, is it the caching mechanism of Vue Query itself, or is it only the staleTime, or are there other mechanisms to avoid duplicate API requests from both the Server and Client sides? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
https://tanstack.com/query/latest/docs/framework/vue/guides/ssr#staleness-is-measured-from-when-the-query-was-fetched-on-the-server