Replies: 2 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
0 replies
-
I couldn't find a I came up with a workaround: const qc = useQueryClient();
useQuery({
staleTime: ({ queryKey }) => {
const data = qc.getQueryData(queryKey);
// ...
return staleTime;
}
}); |
Beta Was this translation helpful? Give feedback.
1 reply
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
Currently, the staleTime option in useQuery is determined when the query is initially created and cannot be modified later. However, there are scenarios where the optimal staleTime depends on the response from the query itself (for example, when the API provides a recommended caching duration).
It would be highly beneficial if staleTime could be updated dynamically based on the data returned from the query.
Current Behavior:
Desired Behavior:
Possible Solutions:
Why This Feature Is Needed:
In my use case, files fetched from an API become invalid after a certain period, and the API explicitly provides a timeout value indicating when the data becomes stale. Being able to directly use this timeout value as staleTime would simplify caching logic significantly, ensuring optimal and accurate cache handling without manual invalidation or additional logic.
Is there a best practice for this problem?
Beta Was this translation helpful? Give feedback.
All reactions