What are the eviction rule for apollo-cache-inmemory?

1.3k Views Asked by At

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

There are 1 best solutions below

0
On

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:

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.