Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clean all cache data?

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.

like image 947
Cem Kaan Avatar asked Dec 06 '25 08:12

Cem Kaan


1 Answers

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()
like image 123
woai3c Avatar answered Dec 07 '25 23:12

woai3c



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!