Apollo client 3 evict object from cache
Asked Answered
C

1

5

Using apollo client 3. Queried all countries and want to remove one country from cache and re-render UI.

Codesandbox

Tried like below;

onClick={() => {
 cache.evict({ id: `Country:${country.code}` });
 cache.gc();
}}

But didn't work. How to evict a country?

Chopin answered 18/10, 2020 at 15:59 Comment(0)
C
10

Eviction should be used this way;

onClick={() => {
   cache.evict({ id: cache.identify(country) });
   cache.gc();
}}

Now the country removed and page rerendered. Sandbox updated

Chopin answered 19/10, 2020 at 20:49 Comment(2)
I get TypeError: cache.identify is not a function in the console?Mountbatten
when hover over cache, it should be infered as InMemoryCache.Chopin

© 2022 - 2024 — McMap. All rights reserved.