Skip to content

Commit

Permalink
Align naming of resetResultCache and resetResultIdentities.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Jun 28, 2021
1 parent 1360139 commit 2118266
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/cache/inmemory/__tests__/entityStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe('EntityStore', () => {
// Now discard cache.storeReader.canon as well.
expect(cache.gc({
resetResultCache: true,
preserveCanon: false,
resetResultIdentities: true,
})).toEqual([]);

const resultAfterFullGC = cache.readQuery({ query });
Expand Down
24 changes: 13 additions & 11 deletions src/cache/inmemory/inMemoryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
this.resetResultCache();
}

private resetResultCache(preserveCanon = true) {
private resetResultCache(resetResultIdentities?: boolean) {
const previousReader = this.storeReader;

// The StoreWriter is mostly stateless and so doesn't really need to be
Expand All @@ -121,11 +121,9 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
cache: this,
addTypename: this.addTypename,
resultCacheMaxSize: this.config.resultCacheMaxSize,
canon: (
preserveCanon &&
previousReader &&
previousReader.canon
) || void 0,
canon: resetResultIdentities
? void 0
: previousReader && previousReader.canon,
}),
);

Expand Down Expand Up @@ -285,14 +283,18 @@ export class InMemoryCache extends ApolloCache<NormalizedCacheObject> {
// this.{store{Reader,Writer},maybeBroadcastWatch}. Defaults to false.
resetResultCache?: boolean;
// If resetResultCache is true, this.storeReader.canon will be preserved by
// default, but can also be discarded by passing false for preserveCanon.
// Defaults to true, but has no effect if resetResultCache is false.
preserveCanon?: boolean;
// default, but can also be discarded by passing resetResultIdentities:true.
// Defaults to false.
resetResultIdentities?: boolean;
}) {
canonicalStringify.reset();
const ids = this.optimisticData.gc();
if (options && options.resetResultCache && !this.txCount) {
this.resetResultCache(options.preserveCanon);
if (options && !this.txCount) {
if (options.resetResultCache) {
this.resetResultCache(options.resetResultIdentities);
} else if (options.resetResultIdentities) {
this.storeReader.resetCanon();
}
}
return ids;
}
Expand Down
3 changes: 3 additions & 0 deletions src/cache/inmemory/readFromStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ export class StoreReader {
)<Record<string, any>, SelectionSetNode>();

public canon: ObjectCanon;
public resetCanon() {
this.canon = new ObjectCanon;
}

constructor(config: StoreReaderConfig) {
this.config = {
Expand Down

0 comments on commit 2118266

Please sign in to comment.