3

Is it possible to use garbage collection cache.gc() with vue-apollo?

Is there any way to clean all store cache data?

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.

Cem Kaan
  • 2,086
  • 1
  • 24
  • 55

1 Answers1

1

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()
woai3c
  • 51
  • 6