How does the Graphcache work? #1822
-
Hi, I'm a bit confused about the Graphcache. Does it automatically cache, or not do I need to specify it all manually? I've read the docs but it's still a bit confusing. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
It's a cache just like the other one but the difference is how it caches, as the explanation details, graphCache is a normalized cache and the default is a document cache. The normalized cache will gather query-results and cache appropriately but sometimes when we're mutating data you'll need to help it out a bit. When an entity is present in the cache and we update it the normalized cache will be able to reconcile that against the data it has. { id: 1, text: 'hi', __typename: 'Todo' } When the cache sees a response like this it's easy to for instance update the
The manual work only happens on select mutations and you'll notice when this happens because you'll see stale data. |
Beta Was this translation helpful? Give feedback.
It's a cache just like the other one but the difference is how it caches, as the explanation details, graphCache is a normalized cache and the default is a document cache.
The normalized cache will gather query-results and cache appropriately but sometimes when we're mutating data you'll need to help it out a bit. When an entity is present in the cache and we update it the normalized cache will be able to reconcile that against the data it has.
When the cache sees a response like this it's easy to for instance update the
Todo:1.text
tohi
rather than what it was before, however when we are deleting/adding entities we'll need to help the cache a bi…