0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-16 22:50:20 +00:00
query/docs/framework/solid/reference/classes/MutationCache.md
Wonsuk Choi e57f8163b1
docs(query-core): add JSDoc across the package and expose it in generated reference docs (#11438)
* docs(query-core): add JSDoc across the package and expose it in generated reference docs

* docs(config.json): add sidebar entries for newly generated query-core reference docs

* docs(query-core): migrate remaining prose from the legacy 'docs/reference' pages into JSDoc

* docs(query-core): remove legacy 'docs/reference' pages superseded by the generated reference

* docs(query-core): regenerate reference docs after merging main

* docs(query-core): document missing default values for MutationOptions, combine, and QueryFilters.type

* fix(query-devtools): drop unnecessary 'query-core' project reference

* docs(query-core): document missing default values and normalize 'Defaults to' spacing

* docs(query-core): fix 'environmentManager' JSDoc example
2026-09-07 18:22:38 +02:00

5.9 KiB

id title
MutationCache MutationCache

Defined in: packages/query-core/src/mutationCache.ts:124

The MutationCache is the storage for mutations.

Normally, you will not interact with the MutationCache directly and instead use a QueryClient. You can subscribe to it (inherited from Subscribable) to be informed of safe/known updates to the cache, such as mutations being added, removed, or updated.

Example

const unsubscribe = mutationCache.subscribe((event) => {
  console.log(event.type, event.mutation)
})

Extends

  • Subscribable<MutationCacheListener>

Constructors

Constructor

new MutationCache(config): MutationCache;

Defined in: packages/query-core/src/mutationCache.ts:129

Parameters

config

MutationCacheConfig = {}

Returns

MutationCache

Overrides

Subscribable<MutationCacheListener>.constructor

Properties

config

config: MutationCacheConfig = {};

Defined in: packages/query-core/src/mutationCache.ts:129


listeners

protected listeners: Set<MutationCacheListener>;

Defined in: packages/query-core/src/subscribable.ts:2

Inherited from

Subscribable.listeners

Methods

clear()

clear(): void;

Defined in: packages/query-core/src/mutationCache.ts:236

Removes all mutations from the cache.

Returns

void

Example

const mutationCache = queryClient.getMutationCache()

mutationCache.clear()

find()

find<TData, TError, TVariables, TOnMutateResult>(filters): 
  | Mutation<TData, TError, TVariables, TOnMutateResult>
  | undefined;

Defined in: packages/query-core/src/mutationCache.ts:278

A slightly more advanced method that can be used to get an existing mutation instance from the cache. If the mutation does not exist, undefined is returned.

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

Type Parameters

TData

TData = unknown

TError

TError = Error

TVariables

TVariables = any

TOnMutateResult

TOnMutateResult = unknown

Parameters

filters

MutationFilters

Returns

| Mutation<TData, TError, TVariables, TOnMutateResult> | undefined

See

MutationCache#findAll

Example

const mutationCache = queryClient.getMutationCache()

const mutation = mutationCache.find({ mutationKey: ['addPost'] })

findAll()

findAll(filters): Mutation<unknown, Error, unknown, unknown>[];

Defined in: packages/query-core/src/mutationCache.ts:308

An even more advanced method that can be used to get existing mutation instances from the cache that match the given filters. If no mutations match, an empty array is returned.

This is not typically needed for most applications, but can come in handy when needing more information about mutations in rare scenarios.

Parameters

filters

MutationFilters = {}

Returns

Mutation<unknown, Error, unknown, unknown>[]

See

MutationCache#find

Example

const mutationCache = queryClient.getMutationCache()

const mutations = mutationCache.findAll({ mutationKey: ['addPost'] })

getAll()

getAll(): Mutation<unknown, Error, unknown, unknown>[];

Defined in: packages/query-core/src/mutationCache.ts:259

Returns all mutations within the cache.

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

Returns

Mutation<unknown, Error, unknown, unknown>[]

Example

const mutationCache = queryClient.getMutationCache()

const mutations = mutationCache.getAll()

hasListeners()

hasListeners(): boolean;

Defined in: packages/query-core/src/subscribable.ts:19

Returns

boolean

Inherited from

Subscribable.hasListeners

onSubscribe()

protected onSubscribe(): void;

Defined in: packages/query-core/src/subscribable.ts:23

Returns

void

Inherited from

Subscribable.onSubscribe

onUnsubscribe()

protected onUnsubscribe(): void;

Defined in: packages/query-core/src/subscribable.ts:27

Returns

void

Inherited from

Subscribable.onUnsubscribe

subscribe()

subscribe(listener): () => void;

Defined in: packages/query-core/src/subscribable.ts:8

Parameters

listener

MutationCacheListener

Returns

(): void;
Returns

void

Inherited from

Subscribable.subscribe