The MutationCache is the storage for mutations.

Normally, you will not interact with the MutationCache directly and instead use the QueryClient.

import { MutationCache } from '@sveltestack/svelte-query'
const mutationCache = new MutationCache()

Its available methods are:


getAll returns all mutations within the cache.

Note: This is not typically needed for most applications, but can come in handy when needing more information about a mutation in rare scenarios

const mutations = mutationCache.getAll()


  • Mutation[]
    • Mutation instances from the cache


The subscribe method can be used to subscribe to the mutation cache as a whole and be informed of safe/known updates to the cache like mutation states changing or mutations being updated, added or removed.

const callback = mutation => {
const unsubscribe = mutationCache.subscribe(callback)


  • callback: (mutation?: Mutation) => void
    • This function will be called with the mutation cache any time it is updated.


  • unsubscribe: Function => void
    • This function will unsubscribe the callback from the mutation cache.


The clear method can be used to clear the cache entirely and start fresh.

Was this page helpful?

Subscribe to our newsletter

The latest TanStack news, articles, and resources, sent to your inbox.

    I won't send you spam.

    Unsubscribe at any time.

    © 2020 Tanner Linsley. All rights reserved.