Skip to content

Commit

Permalink
Avoid updating cache watches when fetchPolicy is no-cache (#4573)
Browse files Browse the repository at this point in the history
Avoid updating (and later invalidating) cache watches when fetchPolicy is no-cache.

Part of #3452.
  • Loading branch information
bradleyayers authored and benjamn committed Apr 8, 2019
1 parent 5c0760b commit 58cb6d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
```
which allows the client to avoid taking defensive snapshots of past results using `cloneDeep`, as explained by [@benjamn](https://github.com/benjamn) in [#4543](https://github.com/apollographql/apollo-client/pull/4543).

- Avoid updating (and later invalidating) cache watches when `fetchPolicy` is `'no-cache'`. <br/>
[@bradleyayers](https://github.com/bradleyayers) in [PR #4573](https://github.com/apollographql/apollo-client/pull/4573), part of [issue #3452](https://github.com/apollographql/apollo-client/issues/3452)

### Apollo Cache In-Memory

- Support `new InMemoryCache({ freezeResults: true })` to help enforce immutability. <br/>
Expand Down
4 changes: 3 additions & 1 deletion packages/apollo-client/src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,9 @@ export class QueryManager<TStore> {
const requestId = this.generateRequestId();

// set up a watcher to listen to cache updates
const cancel = this.updateQueryWatch(queryId, query, updatedOptions);
const cancel = fetchPolicy !== 'no-cache'
? this.updateQueryWatch(queryId, query, updatedOptions)
: undefined;

// Initialize query in store with unique requestId
this.setQuery(queryId, () => ({
Expand Down

0 comments on commit 58cb6d5

Please sign in to comment.