-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
invalidateTags only seems to work with a setTimeout #4706
Comments
What are you trying to accomplish? Are you trying to wait for all the invalidated cache entry requests to complete?
If you need to know when the requests are done, you'd probably need: |
@markerikson ah i see thanks! this is what i was trying to accomplish:
so here is my problem, (see first message): inside i have an api call that returns cached data: // fetch weather for current position
const promiseromise = thunkApi
.dispatch(
Weather.endpoints.fetchWeatherByCoordinate.initiate(
currentLocation.position.coordinate,
),
)
.unwrap(); even when before that i called After the invalidateTags call, I expected all cached data would have been invalidated and the next API call would have been fresh data. EDIT: I followed your recommendation but it still did not work: const fetchAlerts = async () => {
prettyLog('Fetching alerts for locations');
dispatch(Weather.util.invalidateTags([ApiCacheTags.FetchWeather]));
// only works w this delay, if i remove this delay then the call in
// syncWeatherForCurrentLocation returns cached data
await new Promise(resolve => setTimeout(resolve, 1000));
// this return empty array always, with or without the delay above
const queries = await Promise.all(
dispatch(Weather.util.getRunningQueriesThunk()),
);
prettyLog('Cache invalidation complete', { queries });
dispatch(syncWeatherForCurrentLocation()),
}; |
Invalidation kicks off a new request, but it doesn't remove the existing cache entry. |
Hey there!
When I get a web socket update I want to refetch data.
This setup is working (notice setTimeout):
This is NOT working:
I thought invalidateTags was a synchronous call. How would I await it here? Or what else am I missing?
The text was updated successfully, but these errors were encountered: