japheth
japheth

Reputation: 473

RTK Query Invalidate Provided tags after some seconds

I am working on a project that I am using RTK Query to perform API calls. SO, the system is highly data dependent. There is this one scenario where parcels are dispatched to several vehicles. So, the user has to get a list of available parcels and dispatch. This can happen subsequently, like within 5 to 10 seconds. So, the user will make a call, get available parcels for dispatch, dispatch some to a vehicle, then get back to the list of available parcels for dispatch and dispatch to another vehicle. This is the code I am using to get these parcels:

getParcelsAvailableForDispatch: builder.query({
    query: () => `${SLICE_URL}/available-for-dispatch`,
    providesTags: (result, error, id) => [{ type: 'Parcel', id }],
}),

Challenge is, it takes long for this list of parcels to be invalidated from the cache, hence, after dispatching some, if the user goes back to the list of parcels, the same parcels will still be there. Is there a way I can specify an expiry period or invalidation period for this, say like after every 5 seconds? Note: The tag for dispatching parcels is not the same as that of getting parcels available for dispatch.

Upvotes: 2

Views: 6778

Answers (1)

Amir Rezvani
Amir Rezvani

Reputation: 1504

your answer is here just use keepUnusedDataFor.

Upvotes: 3

Related Questions