<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/medium-fk5u88jjj" -->

---
title: Medium | daily.dev
description: A comprehensive guide to RTK Query's cache management system using Tags. Covers the core concepts of tagTypes, providesTags, and invalidatesTags with...
canonical: https://daily.dev/posts/medium-fk5u88jjj
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Medium | daily.dev
og:description: A comprehensive guide to RTK Query's cache management system using Tags. Covers the core concepts of tagTypes, providesTags, and invalidatesTags with...
og:url: https://daily.dev/posts/medium-fk5u88jjj
og:image: https://api.daily.dev/og/posts/FK5U88jjJ.png
og:image:alt: Medium
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Medium

**[Medium](https://daily.dev/sources/medium_js)** · 9 min read · 2 upvotes · 0 comments

## Summary

A comprehensive guide to RTK Query's cache management system using Tags. Covers the core concepts of tagTypes, providesTags, and invalidatesTags with step-by-step examples. Explains how stale cache problems arise, how Tags label cached data, and how mutations automatically trigger refetches when tags are invalidated. Also covers dynamic tags for per-item cache control, cache lifetime configuration via keepUnusedDataFor, refetch options (on mount, window focus, reconnect), common beginner mistakes, and production best practices.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://medium.com/@wm4012388/redux-toolkit-query-rtk-query-complete-guide-to-cache-management-with-tags-tagtypes-521c9d34c3d7>

## Questions this post answers

### How do providesTags and invalidatesTags work together in RTK Query?

providesTags attaches a label like "Users" to cached query results, marking which cache category that data belongs to. invalidatesTags, set on a mutation, marks that same label as outdated after the mutation succeeds, causing RTK Query to automatically refetch any active query with the matching tag, updating the UI without manual dispatch or page refresh.

_See how developers on daily.dev share patterns for keeping RTK Query caches in sync after mutations._

### How do I set up dynamic tags per item in RTK Query instead of invalidating the whole list?

Use a function for providesTags that maps each returned record to an object like { type: "Users", id }, plus a { type: "Users", id: "LIST" } entry for the collection. This gives each user its own tag (e.g., Users-1, Users-2), letting mutations invalidate a single item's tag instead of refetching the entire list, which is common in enterprise applications.

_Developers optimizing RTK Query cache granularity often compare dynamic tagging approaches on daily.dev._

### What is the default cache lifetime in RTK Query and how do I change it?

RTK Query keeps unused cached data for 60 seconds by default after the last component stops using a query, then removes it from memory. This can be customized per endpoint with the keepUnusedDataFor option, for example setting it to 120 to retain data for 120 seconds; longer values reduce API calls but increase memory usage.

_Track caching trade-offs like this alongside other RTK Query tips curated on daily.dev._

## Similar posts on daily.dev

- [Cache: Stop Asking the Database the Same Question](https://daily.dev/posts/cache-stop-asking-the-database-the-same-question-qjeabvnp4) · Medium · 1 upvotes · 1 comments
- [Caching with TanStack Query](https://daily.dev/posts/caching-with-tanstack-query-vcjkfwju7) · Telerik · 0 upvotes · 0 comments
- [A gentle introduction to TanStack Query](https://daily.dev/posts/a-gentle-introduction-to-tanstack-query-e5yjmxkk9) · Neciu Dan · 79 upvotes · 5 comments
- [A complete guide to HTTP caching](https://daily.dev/posts/a-complete-guide-to-http-caching-glkmld7xp) · Programming Digest · 97 upvotes · 3 comments
- [Handling Mutations with TanStack Query for Vue](https://daily.dev/posts/handling-mutations-with-tanstack-query-for-vue-abiiglpxm) · Telerik · 13 upvotes · 0 comments

---

Tags: [#react](https://daily.dev/tags/react)

[View this post on daily.dev](https://daily.dev/posts/medium-fk5u88jjj)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Medium","url":"https://daily.dev/posts/medium-fk5u88jjj","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/medium-fk5u88jjj"},"datePublished":"2026-07-26T15:13:40.398Z","dateModified":"2026-09-14T06:15:30.864Z","description":"A comprehensive guide to RTK Query's cache management system using Tags. Covers the core concepts of tagTypes, providesTags, and invalidatesTags with...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/58cb507e0d4e363fc080edb973bc018a?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/58cb507e0d4e363fc080edb973bc018a?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Medium","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/medium","url":"https://daily.dev/sources/medium_js"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/medium-fk5u88jjj","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"react","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"Medium"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/medium-fk5u88jjj#faq","mainEntity":[{"@type":"Question","name":"How do providesTags and invalidatesTags work together in RTK Query?","acceptedAnswer":{"@type":"Answer","text":"providesTags attaches a label like \"Users\" to cached query results, marking which cache category that data belongs to. invalidatesTags, set on a mutation, marks that same label as outdated after the mutation succeeds, causing RTK Query to automatically refetch any active query with the matching tag, updating the UI without manual dispatch or page refresh. See how developers on daily.dev share patterns for keeping RTK Query caches in sync after mutations."}},{"@type":"Question","name":"How do I set up dynamic tags per item in RTK Query instead of invalidating the whole list?","acceptedAnswer":{"@type":"Answer","text":"Use a function for providesTags that maps each returned record to an object like { type: \"Users\", id }, plus a { type: \"Users\", id: \"LIST\" } entry for the collection. This gives each user its own tag (e.g., Users-1, Users-2), letting mutations invalidate a single item's tag instead of refetching the entire list, which is common in enterprise applications. Developers optimizing RTK Query cache granularity often compare dynamic tagging approaches on daily.dev."}},{"@type":"Question","name":"What is the default cache lifetime in RTK Query and how do I change it?","acceptedAnswer":{"@type":"Answer","text":"RTK Query keeps unused cached data for 60 seconds by default after the last component stops using a query, then removes it from memory. This can be customized per endpoint with the keepUnusedDataFor option, for example setting it to 120 to retain data for 120 seconds; longer values reduce API calls but increase memory usage. Track caching trade-offs like this alongside other RTK Query tips curated on daily.dev."}}]}
```

