Skip to content

Mutation Cache Duration #2920

@TkDodo

Description

@TkDodo

As discussed in this discussion, the MutationCache is currently ever growing. This can be a problem because mutations are not shared like queries are, and are also never garbage collected. If mutations return big responses, those will be held in memory indefinitely.

Proposed solution

Add a cacheTime to MutationCache, and default to 5 minutes (same time as for queries). We can't remove mutations from the cache instantly after the last observer unmounts, because callacks on useMutation might fire after that.

For that, we also need to notify the cache when an observer is added or removed for a mutation. The code for scheduling garbageCollection could be shared between queries and mutations via a base class that both Query and Mutation could extend.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions