Is it possible to use garbage collection cache.gc() with vue-apollo?
For example, is it possible to run it inside a lifecycle?
<script>
import { apolloClient } from "@/main";
export default {
mounted() {
this.$apollo.cache.gc();
// or may be this.$apollo.queries.birds.cache.gc();
// or this.$store.cache.gc();
},
};
</script>
I can not get a list after the first register. I have to refresh it.
first, init apollo client:
import { ApolloClients } from '@vue/apollo-composable';
import { createApp, provide, h } from 'vue';
import App from './App.vue';
// other ...
const apolloClient = new ApolloClient({
link: from([errorLink, requestInterceptor, authLink, traceLink, httpLink]),
cache: new InMemoryCache({
addTypename: false
})
});
const app = createApp({
setup() {
provide(ApolloClients, {
default: apolloClient
});
},
render: () => h(App)
});
export default apolloClient
then, you can clear apollo network cache whenever you want:
import apolloClient from 'xxx.ts'
apolloClient.cache.reset()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With