Reputation: 629
We are in the process of slowly adding the graphql to our react project and replacing the existing redux integration. So I am trying to understand caching in the apollo and saw two things.
We have query to call list of apps on the home page and this list of apps will be using on some other page. So one option i tried is to call the list of apps query in the parent container and use the client.readQuery in the child pages, so that the call to the graphql server will be happened only in the container and in the other pages it will get called from the cache. But i saw some posts regarding the use of apollo-link-state in scenarios similar to this. So what is the best method to use here and when to use apollo-cache-inmemory and when to use apollo-link-state?
Upvotes: 3
Views: 862
Reputation: 5414
You shouldn't compare apollo-cache-inmemory
directly to apollo-link-state
. apollo-cache-inmemory
is used to handle caching on Apollo Client
, you don't have to do write any custom code for it to work (apart from just telling Apollo Client
to use it). Any data that you fetch from api
are cached automatically.
apollo-link-state
however is meant for client-side caching, e.g. the NetworkStatus of the browser, or current active tab. States that usually not send back to a backend server.
So, you only need to consider whether you need client-side caching or not. In most cases that I saw, a project would eventually end up using both.
Upvotes: 6