-
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 resultCacheMaxSize #8107
add resultCacheMaxSize #8107
Conversation
@sofianhn: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
patches/optimism+0.15.0.patch
Outdated
@@ -0,0 +1,47 @@ | |||
diff --git a/node_modules/optimism/lib/bundle.cjs.js b/node_modules/optimism/lib/bundle.cjs.js |
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.
the patched package is included here for reference, here is the upstream PR: benjamn/optimism#189
I added a post install for For me running |
@sofianhn Thanks for this! I/we will take a deeper look this week, but a couple things jumped out at me right away:
|
On second thought @sofianhn, would you mind separating the |
Awesome, looking forward, I will split this to 2 PRs. |
2ecbfb9
to
482f4d8
Compare
This PR now tracks only adding |
@@ -285,8 +324,7 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> { | |||
} | |||
|
|||
public reset(): Promise<void> { | |||
this.optimisticData = this.optimisticData.prune(); | |||
this.data.clear(); | |||
this.init(); |
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.
Thanks to this change, resetting the cache now dumps this.storeReader
and all other result-caching-related data, and replaces them with empty data structures.
constructor(private config: StoreReaderConfig) { | ||
this.config = { addTypename: true, ...config }; | ||
|
||
this.executeSelectionSet = wrap(options => this.execSelectionSetImpl(options), { |
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.
I don't think these initializations make sense to move to an init
or reset
method (like I did in InMemoryCache
), since it's simpler to dump/replace the whole StoreReader
object, and let the original one be garbage collected.
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.
LGTM with a few tweaks!
Give me a day or two to whip up some optimism
functionality that should make the rest of your original PR easier from the perspective of InMemoryCache
. In particular, I think we can reuse the existing dep<TKey>
concept, if we allow dep.forget(key)
as well as dep.dirty(key)
, where forgetting causes the parent Entry
to be forgotten (removed from the LRU cache, not just dirtied).
These changes have been published in |
Per the conversation in apollographql/apollo-feature-requests#289, this PR is proposing two changes:
Add
resultCachMaxSize
configThis will allow customizing the max size of caches used for
resultCaching
.const cache = new InMemoryCache({ resultCachMaxSize: 5000 });
Add automatic clean up for the caches in
executeSelectionSet
and inexecuteSubSelectedArray
upon eviction of related entries.