mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-27 20:10:58 +00:00
1.2 KiB
1.2 KiB
Endpoint Lifecycle
Invalidation rule
When a mutation invalidates tags:
- active subscribers refetch
- inactive cache entries are removed
- removed entries fetch again only when something subscribes later
That behavior is deliberate; invalidation is not a background "refresh everything" switch.
Document cache tradeoff
RTK Query is a document cache, not a normalized entity graph cache.
Use RTK Query by default when:
- the data comes from request/response APIs
- document caching is acceptable
- tag invalidation and endpoint lifecycles solve the problem
Reach for a different tool when:
- the real requirement is a normalized graph cache
- the stack already has a domain-specific normalized client that fits better
If normalized caching is mandatory and no better library is already in the stack, a slice plus thunk flow may be the fallback.
Useful endpoint options
providesTags: tell RTK Query what cache entries this query representsinvalidatesTags: tell RTK Query what a mutation dirtiesonQueryStarted: optimistic and pessimistic updates tied to a requestonCacheEntryAdded: long-lived subscriptions such as streaming datakeepUnusedDataFor: how long inactive cache entries stay around