Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache query documents transformed by InMemoryCache.
After #3444 removed `Map`-based caching for `addTypenameToDocument` (in order to fix memory leaks), the `InMemoryCache#transformDocument` method now creates a completely new `DocumentNode` every time it's called (assuming this.addTypename is true, which it is by default). This commit uses a `WeakMap` to cache calls to `addTypenameToDocument` in `InMemoryCache#transformDocument`, so that repeated cache reads will no longer create an unbounded number of new `DocumentNode` objects. The benefit of the `WeakMap` is that it does not prevent its keys (the original `DocumentNode` objects) from being garbage collected, which is another way of preventing memory leaks. Note that `WeakMap` may have to be polyfilled in older browsers, but there are many options for that. This optimization will be important for #3394, since the query document is involved in cache keys used to store cache partial query results. cc @hwillson @jbaxleyiii @brunorzn
- Loading branch information