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