-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added custom objectCache root in inMemoryCache #5601
Conversation
Thanks for following the release and taking the initiative to propose and implement this change! To be completely honest with you, the For example, we are considering changing Also, if you're envisioning persisting every individual read or write to IndexedDB or some similar persistent storage API, I would just note that the latency for those APIs is pretty awful (5-10ms+ for single reads), so you should really prefer to write the whole |
Hi @benjamn, thanks for the quick reply. I proposed a PR in draft because I imagined that cache management was still evolving. You're absolutely right about the latency in interfacing with storage. This was the reason why my cache library handles reading from storage only when the application starts for state reconciliation... Obviously in react-native contexts it is remarkably efficient (they implement multiSet / multiRemove), in web contexts the throttle value must be correctly managed (for now). In the next versions of the library I wanted to give the opportunity to manage the storage writing in a single key (similar to cache.toObject()). Finally, it can also be used as a simple InMemory cache using the disablePersist parameter. For a perfect integration with Apollo it would be useful to manage all the data that guarantee the consistency of the cache, the cache data and the references to the persisted queries (rootIds), through an object like objectCache and its possible configuration. |
I agree, the PR has been used to inform you of this need and to give my availability to implement it. To ask for some information do you recommend opening an issue or is there an alternative channel for the v3 release? Anyway, I created two example projects (one with nextjs ssr & one simple web app) to test apollo-client 3.0 and integration with my libraries so If you have any doubt where I can help, let me know |
It would be interesting to extend this discussion with the apollo-cache-persist roadmap. In addition to the possibility of configuring different storage, there are other configurable properties that are often useful:
|
Codecov Report
@@ Coverage Diff @@
## master #5601 +/- ##
==========================================
+ Coverage 95.37% 95.39% +0.02%
==========================================
Files 88 89 +1
Lines 3653 3671 +18
Branches 903 905 +2
==========================================
+ Hits 3484 3502 +18
Misses 146 146
Partials 23 23
Continue to review full report at Codecov.
|
Eta? |
Hi @benjamn, Also, what about apollo-cache-persist do you plan to upgrade it to support apollo v3? |
Apollo-cache-persist is working with Apollo v3 already. We needed to push different package as the community did not have access to the v2 package Big topic is now support for reactive variables: Looking to some opinions from the core team on it as not sure if makes sense to persist them. |
@morrys Make sure you're using the new |
@benjamn do you still plan to include persistence at some point into Apollo-Client. Any cons about adapting persistence into the core? |
hi @benjamn, I noticed that in the sources the retain function is called https://github.com/apollographql/apollo-client/blob/release-3.3/src/cache/inmemory/writeToStore.ts#L114 but not the release function nor the function gc. Is this the intended behavior or is it evolving? In summary, should the management of retain, release, evict and gc be implemented in the application without any automatisms present in the library? Thanks |
Hey all 👋! I'm doing a bit of housekeeping on some of our older PRs/issues and noticed this PR. Since we are now well into 3.0 and this is 3 years old, I'm going to close this. Thanks for the discussion and ideas! |
Hello everybody,
I would like to take advantage of release 3 to propose this PR that implements a feature that I requested here: apollographql/apollo-feature-requests#154
This change allows you to use a custom object cache in EntityCache.Root.
My main use is in the management of the apollo cache persistence and the management of the offline application: morrys/wora#25
But it can also be used to monitor Apollo's cache.
In the file inMemoryCache.ts the main change is this: https://github.com/apollographql/apollo-client/compare/release-3.0...morrys:154-v3-custom-object-cache?expand=1#diff-add1f566156c3d8d297056b5439e0f01R72
The PR is in draft because I would like to discuss it with you ( @hwillson, @benjamn ).
Thanks,
Lorenzo