Open History to see the last commit
1---
2id: MutationCache
3title: MutationCache
4---
5β
6Defined in: [packages/vue-query/src/mutationCache.ts:15](https://github.com/TanStack/query/blob/main/packages/vue-query/src/mutationCache.ts#L15)
7β
8Vue-aware subclass of `@tanstack/query-core`'s `MutationCache`. `find`/`findAll` also accept a
9MaybeRefDeep filters object, so `ref`s can be passed directly without unwrapping. Access it via
10`queryClient.getMutationCache()` β `QueryClient` constructs one of these by default.
11β
12## Extends
13β
14- `MutationCache`
15β
16## Constructors
17β
18### Constructor
19β
20```ts
21new MutationCache(config?: MutationCacheConfig): MutationCache;
22```
23β
24Defined in: [packages/query-core/src/mutationCache.ts:128](https://github.com/TanStack/query/blob/main/packages/query-core/src/mutationCache.ts#L128)
25β
26#### Parameters
27β
28##### config?
29β
30[`MutationCacheConfig`](../interfaces/MutationCacheConfig.md) = `{}`
31β
32#### Returns
33β
34`MutationCache`
35β
36#### Inherited from
37β
38```ts
39MC.constructor
40```
41β
42## Properties
43β
44### config
45β
46```ts
47config: MutationCacheConfig = {};
48```
49β
50Defined in: [packages/query-core/src/mutationCache.ts:128](https://github.com/TanStack/query/blob/main/packages/query-core/src/mutationCache.ts#L128)
51β
52#### Inherited from
53β
54```ts
55MC.config
56```
57β
58## Methods
59β
60### clear()
61β
62```ts
63clear(): void;
64```
65β
66Defined in: [packages/query-core/src/mutationCache.ts:262](https://github.com/TanStack/query/blob/main/packages/query-core/src/mutationCache.ts#L262)
67β
68Removes all mutations from the cache.
69β
70#### Returns
71β
72`void`
73β
74#### Example
75β
76```ts
77const mutationCache = queryClient.getMutationCache()
78β
79mutationCache.clear()
80```
81β
82#### Inherited from
83β
84```ts
85MC.clear
86```
87β
88***
89β
90### find()
91β
92```ts
93find<TData, TError, TVariables, TOnMutateResult>(filters: MaybeRefDeep<MutationFilters<unknown, Error, unknown, unknown>>):
94 | Mutation<TData, TError, TVariables, TOnMutateResult>
95 | undefined;
96```
97β
98Defined in: [packages/vue-query/src/mutationCache.ts:16](https://github.com/TanStack/query/blob/main/packages/vue-query/src/mutationCache.ts#L16)
99β
100A slightly more advanced method that can be used to get an existing mutation instance from
101the cache. If the mutation does not exist, `undefined` is returned.
102β
103This is not typically needed for most applications, but can come in handy when needing more
104information about a mutation in rare scenarios.
105β
106#### Type Parameters
107β
108##### TData
109β
110`TData` = `unknown`
111β
112##### TError
113β
114`TError` = `Error`
115β
116##### TVariables
117β
118`TVariables` = `any`
119β
120##### TOnMutateResult
121β
122`TOnMutateResult` = `unknown`
123β
124#### Parameters
125β
126##### filters
127β
128`MaybeRefDeep`\<[`MutationFilters`](../interfaces/MutationFilters.md)\<`unknown`, `Error`, `unknown`, `unknown`\>\>
129β
130The filters to match. `exact` defaults to `true`.
131β
132#### Returns
133β
134 \| [`Mutation`](Mutation.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>
135 \| `undefined`
136β
137The first matching mutation, or `undefined`.
138β
139#### See
140β
141[MutationCache#findAll](#findall)
142β
143#### Example
144β
145```ts
146const mutationCache = queryClient.getMutationCache()
147β
148const mutation = mutationCache.find({ mutationKey: ['addPost'] })
149```
150β
151#### Overrides
152β
153```ts
154MC.find
155```
156β
157***
158β
159### findAll()
160β
161```ts
162findAll(filters?: MaybeRefDeep<MutationFilters<unknown, Error, unknown, unknown>>): Mutation<unknown, Error, unknown, unknown>[];
163```
164β
165Defined in: [packages/vue-query/src/mutationCache.ts:27](https://github.com/TanStack/query/blob/main/packages/vue-query/src/mutationCache.ts#L27)
166β
167An even more advanced method that can be used to get existing mutation instances from the
168cache that match the given filters. If no mutations match, an empty array is returned.
169β
170This is not typically needed for most applications, but can come in handy when needing more
171information about mutations in rare scenarios.
172β
173#### Parameters
174β
175##### filters?
176β
177`MaybeRefDeep`\<[`MutationFilters`](../interfaces/MutationFilters.md)\<`unknown`, `Error`, `unknown`, `unknown`\>\> = `{}`
178β
179The filters to match. Without filters, every mutation is returned.
180β
181#### Returns
182β
183[`Mutation`](Mutation.md)\<`unknown`, `Error`, `unknown`, `unknown`\>[]
184β
185The matching mutations.
186β
187#### See
188β
189[MutationCache#find](#find)
190β
191#### Example
192β
193```ts
194const mutationCache = queryClient.getMutationCache()
195β
196const mutations = mutationCache.findAll({ mutationKey: ['addPost'] })
197```
198β
199#### Overrides
200β
201```ts
202MC.findAll
203```
204β
205***
206β
207### getAll()
208β
209```ts
210getAll(): Mutation<unknown, Error, unknown, unknown>[];
211```
212β
213Defined in: [packages/query-core/src/mutationCache.ts:285](https://github.com/TanStack/query/blob/main/packages/query-core/src/mutationCache.ts#L285)
214β
215Returns all mutations within the cache.
216β
217This is not typically needed for most applications, but can come in handy when needing more
218information about a mutation in rare scenarios.
219β
220#### Returns
221β
222[`Mutation`](Mutation.md)\<`unknown`, `Error`, `unknown`, `unknown`\>[]
223β
224Every mutation in the cache.
225β
226#### Example
227β
228```ts
229const mutationCache = queryClient.getMutationCache()
230β
231const mutations = mutationCache.getAll()
232```
233β
234#### Inherited from
235β
236```ts
237MC.getAll
238```
239β
240***
241β
242### hasListeners()
243β
244```ts
245hasListeners(): boolean;
246```
247β
248Defined in: [packages/query-core/src/subscribable.ts:43](https://github.com/TanStack/query/blob/main/packages/query-core/src/subscribable.ts#L43)
249β
250Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.
251β
252#### Returns
253β
254`boolean`
255β
256`true` if at least one listener is registered.
257β
258#### Inherited from
259β
260```ts
261MC.hasListeners
262```
263β
264***
265β
266### subscribe()
267β
268```ts
269subscribe(listener: MutationCacheListener): () => void;
270```
271β
272Defined in: [packages/query-core/src/subscribable.ts:28](https://github.com/TanStack/query/blob/main/packages/query-core/src/subscribable.ts#L28)
273β
274Registers a listener to be called on every update this object notifies about. Returns a function
275that removes the listener again β call it to stop listening. The base class never drops a listener
276on its own, though some subclasses clear all of theirs in `destroy()`.
277β
278#### Parameters
279β
280##### listener
281β
282`MutationCacheListener`
283β
284Called on each update, with whatever the subclass passes to its subscribers.
285β
286#### Returns
287β
288A function that removes the listener.
289β
290() => `void`
291β
292#### Example
293β
294```ts
295const unsubscribe = subscribable.subscribe(() => {
296 // react to the update
297})
298β
299unsubscribe()
300```
301β
302#### Inherited from
303β
304```ts
305MC.subscribe
306```