-
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
Add options to cache.gc
to enable deleting nonessential/recomputable result caching data
#8421
Conversation
cache.gc
to enable deleting nonessential/recomputable result caching data
0c9dfb7
to
d845072
Compare
d845072
to
07e84a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrote some thoughts. Again I’m not 100% familiar with how advanced caching stuff is supposed to work so my input is limited. My primary concerns are about the API design. Two new boolean options, which seem to be interrelated, and for an advanced use-case which might hard to search for/understand as a non-Apollo Client maintainer. Maybe we can loop in some advanced users like @sofianhn and the documentation team @StephenBarlow for their thoughts?
Also, if there are any relevant issues from users asking for this that I missed I’d love to see them as this could help with the design process.
07e84a0
to
2118266
Compare
@brainkim Thanks for the review! I think I've addressed your concerns, including writing a |
…che. If the cache already has much data in it, the speedup from throwing it all away before replacing it (and thus not having to delete each entity one by one) could be pretty significant.
9d8c3f3
to
bb3daf0
Compare
Ever since #3394,
InMemoryCache
has taken an approach of trading memory for improved efficiency of repeated cache reads.More recently (as of #7439), this result caching system also guarantees cache results will be canonical, a technique that uses memory to store previous canonical objects in an efficient lookup structure (the
ObjectCanon
), to speed up future deep equality comparisons.Although we continue to believe this memory/speed tradeoff is appropriate in most cases, it is conceivable that you might at some point need to reclaim memory more urgently than you need cache performance.
To release all cached result objects (to be garbage collected by JavaScript if otherwise unused) without resetting any actual cache data, this PR allows calling the
cache.gc
(#5310) method with a newresetResultCache: true
option:By default, resetting the result cache will not reset the
ObjectCanon
, which provides===
continuity of cache results even after the result caching system has been completely replaced (as it is when you passresetResultCache: true
tocache.gc
). That preservation is pretty nifty, but if you also want to dump theObjectCanon
for maximum memory savings, then you should also passresetResultIdentities: true
tocache.gc
:These
cache.gc
options are available only onInMemoryCache
(not onApolloCache
), since result caching is anInMemoryCache
-specific concept.The
resetResultCache
andresetResultIdentities
options were the first two options that seemed useful to me, but we can easily add additional options in the future.