Can I reuse the same cache entry for different API requests, where one of them contain a subset of the other? #3552
Unanswered
jimmycallin
asked this question in
Ideas
Replies: 1 comment 2 replies
-
hm, if the goal is to save fetches, why not just use the select option?
with a proper another idea would be to use |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have an API similar to the Contentful API, that enables one to select which fields to fetch in a API request, like such:
Which returns data in this format:
If I were to have a separate query, that only fetches
productName
, like this:I would in theory be able use the same cache entry, since all the select fields are a subset from the first query, which would save the client from having to do another network request.
I imagine it working something like this:
[space_id, { content_type_id, select }]
, whereselect
is a list of all the fields. In the first case, select equals["fields.price", "fields.productName"]
, and in the section, ["fields.productName"]queryKeyEquals
function that can check on a non-serialized queryKey if they are equal. This would allow me to check if theselect
value is a subset of the stored cache entry. (Alternatively, we could use themeta
property to check the same if we don't want to keep queryKeys non-serialized.)select
option available on useQuery to filter the fields manually.Unfortunately there doesn't seem to be any equivalent to the
queryKeyEquals
available. Is this something you have been thinking of introducing, or do you have any other ideas of how I can support this use case?Beta Was this translation helpful? Give feedback.
All reactions