Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache key aliases for better cache redirects #279

Open
macrozone opened this issue Jan 13, 2021 · 0 comments
Open

cache key aliases for better cache redirects #279

macrozone opened this issue Jan 13, 2021 · 0 comments
Labels
📕 cache Feature requests related to the cache

Comments

@macrozone
Copy link

Problem

When fetching a list and than the detail, you might be able to use cache redirects: https://www.apollographql.com/docs/react/caching/advanced-topics/#cache-redirects-using-field-policy-read-functions

However, this only works if your detail will fetch the record by the id (or the same field as the cacheKey), but you might encounter situations where the detail won't be fetched by the id (e.g. fetching by a slug or path, or similar)

its not possible to use cache directs (the read function) in this situation.

See also this disscussion :https://github.com/apollographql/apollo-client/discussions/7574

Possible Solution

in the discussion above i mention a workaround, but it involves internal api as well as a O(n) lookup (basically iterating through all cache objects).

So we should have:

  • a way to define alternate keyFields, for example keyAliasesFields (or any better name), that work similarly to keyFields, but there can be multiple of them.
  • in the read function in the policies we should be able to lookup cache entries by these additional fields (in an eficient way)

Additional context

Apollo client could also warn about these situations, e.g. whenever it does a network request, but the result is already fully in the cache. In these cases you can use cache redirects

@jpvajda jpvajda added the project-apollo-client (legacy) LEGACY TAG DO NOT USE label Jun 1, 2022
@jerelmiller jerelmiller added the 📕 cache Feature requests related to the cache label Apr 6, 2023
@jerelmiller jerelmiller removed the project-apollo-client (legacy) LEGACY TAG DO NOT USE label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📕 cache Feature requests related to the cache
Projects
None yet
Development

No branches or pull requests

3 participants