You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instead of using fetchPolicy we will use: initialFetchPolicy: cache-and-network nextFetchPolicy: cache-first
The idea is that the cache coming from localStorage is considered to be less trustworthy (we weren't connected to the app so objects might have changed) - with this setting we ensure that users see cached data immediately for a fast initial load while updating with fresh data from the network.
On subsequent load, the data should be trustworthy because we'll have websocket so we can keep the current setting which is cache-first.
I tried to do a quick proof of concept:
integrating "await cachePersist" as it's recommended within Apollo provider would have required some refactoring because it's currently initialized in a useMemo ; I'm not sure we need to await for cache persistance since our initialFetchPolicy is "cache-and-network" which will through a request anyway this seems superfluous to me so I left it this way
it worked well for all objects except clientConfig and getCurrentUser which somehow didn't get cached properly. I could see that even if I was setting initialFetchPolicy to cache-first, it was still making a request for those 2 which slowed down the initial rendering of the app. I didn't investigate much further
The text was updated successfully, but these errors were encountered:
As of today we are using "cache-first" strategy and "in-memory" storage.
Instead we would like to introduce a persistent storage through https://github.com/apollographql/apollo-cache-persist/ (most likely LocalStorage).
Instead of using fetchPolicy we will use:
initialFetchPolicy: cache-and-network
nextFetchPolicy: cache-first
The idea is that the cache coming from localStorage is considered to be less trustworthy (we weren't connected to the app so objects might have changed) - with this setting we ensure that users see cached data immediately for a fast initial load while updating with fresh data from the network.
On subsequent load, the data should be trustworthy because we'll have websocket so we can keep the current setting which is cache-first.
I tried to do a quick proof of concept:
useMemo
; I'm not sure we need to await for cache persistance since our initialFetchPolicy is "cache-and-network" which will through a request anyway this seems superfluous to me so I left it this wayThe text was updated successfully, but these errors were encountered: