From what I understand, anything in cache is ephemeral and is subjected to some kind of eviction rule, like LRU. In this case, if we are using the in-memory cache and apollo-link-state to replace redux or vuex, how do we guarantee that some states don't get evicted in the middle of running the application?
1 Answers
As of Apollo Client v2, there is no eviction whatsoever. Based on the comments it might be on the roadmap for v3.
You can check these Github issues for discussion:
- https://github.com/apollographql/apollo-client/issues/3965
- https://github.com/apollographql/apollo-feature-requests/issues/4
- https://github.com/apollographql/apollo-client/issues/621
As for the more general question - in most cases there is no need of such a guarantee. The reason is that cache is completely transparent to the app due to the Apollo Client and React design. When you use a Query
component, your subcomponent will receive data. At that point, you decide what to do if the data is available or not.
For example, if you decide to render a loading spinner if data is not available, then theoretically each time data is evicted, your component will be re-rendered and will show spinner.
I can imagine a case where you might have a long running, async operation (if it's not async then again data cannot be evicted in the middle of it, due to JavaScript execution model). In such a case (rare, but possible), you could potentially copy the data first to local variables etc.

- 2,286
- 2
- 19
- 23