Is cache done by tag or by query & tag? #2938
-
Say I have two queries that can return the same data. One is a single get that returns a single resource, while the other receives an id list and returns a resource list. If I make a request on the single get with id: 1 and provide the tag: {type: "Foo", id: 1} And then in the list query, I do a get with only the same id and provide the same tag: {type: "Foo", id: 1} Does the list query return the cached item or does it perform a new request since it's a different query with different params and endpoint. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Tags have no influence on cache entries. You can have 200 cache entries with completely different contents and the same tag. Tags are like labels you slap onto something to later say "invalidate everything with a red label". Cache entries are a combination of endpoint name and the argument you put into it. So There is no consolidation of similar contents over multiple cache entries. RTK Query is a document cache and every cache entry is completely individual. |
Beta Was this translation helpful? Give feedback.
Tags have no influence on cache entries. You can have 200 cache entries with completely different contents and the same tag. Tags are like labels you slap onto something to later say "invalidate everything with a red label".
Cache entries are a combination of endpoint name and the argument you put into it.
So
useSomeQuery(3)
would end up with a cache entrysome(3)
anduseSomeQuery(5)
would give yousome(5)
. There is a little bit of sanitizing going on, souseSomeQuery({foo:1, bar:2})
will have the same cache entry asuseSomeQuery({bar:2, foo:1})
.There is no consolidation of similar contents over multiple cache entries. RTK Query is a document cache and every cache entry is completely ind…