0

I have a RTK Query endpoint called getUsers which fetches user data in a batch for multiple user ids, provided as an array.

Now I am concerned about caching behaviour. Is there a way I can make RTK Query fetch user data for the missing users only?

for ex

const { data } = useGetUsersQuery([1, 2, 3])

should fetch users 1, 2 and 3

now, afterwards

const { data } = useGetUsersQuery([2, 3, 4, 5])

should treat this api as fetch users 4 and 5, merge with existing data for 2 and 3. And return the entire data?

Blaine
  • 576
  • 9
  • 30

1 Answers1

1

In short, no. RTK Query is not a normalized cache - it is a document cache - which means that every api response is handled completely unrelated to every other api response.

That is mentioned e.g. here in the docs: https://redux-toolkit.js.org/rtk-query/comparison#no-normalized-or-deduplicated-cache

phry
  • 35,762
  • 5
  • 67
  • 81