Allow disabling memoization for all requests of a client #547
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the purpose of this pull request?
Adding an optional flag for HttpClient to disable memoization for all requests by default.
What problem is this solving?
All HttpClient classes have memoization turned on by default, and the only way to turn it off today is by request. And even that way is not helpful for Node.js apps, because the methods provided by subclasses of HttpClient don't provide the option of passing this config anyway.
This new flag for HttpClient allows apps to configure the value for
memoizable
per client, which was previously true for all of them. I set the default value of this new flag totrue
so that there will be no behavior change at all.The reason why we wnant to be able to turn memoization off is because we've noticed that apps like pages-graphql never get hits for those, so having it enabled is a waste of memory and of garbage collector work.
How should this be manually tested?
Link @vtex/api to a local app and try setting this new flag to
false
for some clients. Checking honeycomb traces will show that the setting is now disabled for each outgoing request for that client.I've tested this on pages-graphql, for example and these are the traces:
1. Trace from master workspace, without the change - link. You can see that the
http.cache.memoization.enabled
field is always true for outgoing requests from pages-graphql.2. Trace from a workspace with the change, without setting the new flag - link. You can see the same behavior as in master: the
http.cache.memoization.enabled
field is always true for outgoing requests from pages-graphql.3. Trace from a workspace with the change, setting the new flag to false - link. You can see that the
http.cache.memoization.enabled
field is always false for outgoing requests from pages-graphql. Code for this is in this other PR.Screenshots or example usage
Types of changes