Skip to content
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

Implement InMemoryCache garbage collection and eviction. #5310

Merged
merged 11 commits into from
Sep 13, 2019
Prev Previous commit
Stop automatically retaining entities when reading.
Based on discussion with @hwillson here:
#5310 (comment)
  • Loading branch information
benjamn committed Sep 13, 2019
commit 4b3d78cef63cf66538b3195bb03637c4f37593ce
14 changes: 11 additions & 3 deletions src/cache/inmemory/__tests__/entityCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ describe('EntityCache', () => {
fragment: authorNameFragment,
});

expect(cache.retain('Author:Ray Bradbury')).toBe(1);

expect(ray).toEqual({
__typename: 'Author',
name: 'Ray Bradbury',
Expand Down Expand Up @@ -222,7 +224,14 @@ describe('EntityCache', () => {
},
});

// Nothing left to garbage collect.
expect(cache.gc()).toEqual([]);

expect(cache.release('Author:Ray Bradbury')).toBe(0);

expect(cache.gc()).toEqual([
'Author:Ray Bradbury',
]);

expect(cache.gc()).toEqual([]);
});

Expand Down Expand Up @@ -724,8 +733,7 @@ describe('EntityCache', () => {
},
});

// The book has been retained a couple of times since we've written it
// directly, but J.K. has never been directly written.
expect(cache.retain("Book:031648637X")).toBe(2);
expect(cache.release("Book:031648637X")).toBe(1);
expect(cache.release("Book:031648637X")).toBe(0);

Expand Down
4 changes: 0 additions & 4 deletions src/cache/inmemory/readFromStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,6 @@ export class StoreReader {
cacheRedirects: (config && config.cacheRedirects) || {},
};

// Any IDs read explicitly from the cache (including ROOT_QUERY, most
// frequently) will be retained as reachable root IDs, until released.
store.retain(rootId);

const execResult = this.executeStoreQuery({
query,
objectOrReference: rootId === 'ROOT_QUERY'
Expand Down