@@ -24,7 +24,7 @@ class Controller {
2424 subscribe(endpoint , ... args ): Promise <void >;
2525 unsubscribe(endpoint , ... args ): Promise <void >;
2626 /** ************* Data Access ***************/
27- getResponse(endpoint , ... args , state ): { data, expiryStatus, expiresAt };
27+ getResponse(endpoint , ... args , state ): { data; expiryStatus; expiresAt };
2828 getError(endpoint , ... args , state ): ErrorTypes | undefined ;
2929 snapshot(state : State <unknown >, fetchedAt ? : number ): SnapshotInterface ;
3030 getState(): State <unknown >;
@@ -56,7 +56,9 @@ function CreatePost() {
5656
5757 return (
5858 <form
59- onSubmit = { e => ctrl .fetch (PostResource .getList .push , new FormData (e .target ))}
59+ onSubmit = { e =>
60+ ctrl .fetch (PostResource .getList .push , new FormData (e .target ))
61+ }
6062 >
6163 { /* ... */ }
6264 </form >
@@ -141,6 +143,44 @@ post.pk();
141143- Identical requests are deduplicated globally; allowing only one inflight request at a time.
142144 - To ensure a _ new_ request is started, make sure to abort any existing inflight requests.
143145
146+ ## expireAll({ testKey }) {#expireAll}
147+
148+ Sets all responses' [ expiry status] ( ../concepts/expiry-policy.md ) matching ` testKey ` to [ Stale] ( ../concepts/expiry-policy.md#stale ) .
149+
150+ This is sometimes useful to trigger refresh of only data presently shown
151+ when there are many parameterizations in cache.
152+
153+ ``` tsx
154+ import { type Controller , useController } from ' @data-client/react' ;
155+
156+ const createTradeHandler = (ctrl : Controller ) => async trade => {
157+ await ctrl .fetch (TradeResource .getList .push ({ user: user .id }, trade ));
158+ // highlight-start
159+ ctrl .expireAll (AccountResource .get );
160+ ctrl .expireAll (AccountResource .getList );
161+ // highlight-end
162+ };
163+
164+ function CreateTrade({ id }: { id: string }) {
165+ const handleTrade = createTradeHandler (useController ());
166+
167+ return (
168+ <Form onSubmit = { handleTrade } >
169+ <FormField name = " ticker" />
170+ <FormField name = " amount" type = " number" />
171+ <FormField name = " price" type = " number" />
172+ </Form >
173+ );
174+ }
175+ ```
176+
177+ ::: tip
178+
179+ To reduce load, improve performance, and improve state consistency; it can often be
180+ better to [ include mutation sideeffects in the mutation response] ( /rest/guides/rpc ) .
181+
182+ :::
183+
144184## invalidate(endpoint, ...args) {#invalidate}
145185
146186Forces refetching and suspense on [ useSuspense] ( ./useSuspense.md ) with the same Endpoint
@@ -162,7 +202,7 @@ function ArticleName({ id }: { id: string }) {
162202
163203:::tip
164204
165- To refresh while continuing to display stale data - [Controller.fetch](#fetch) instead .
205+ To refresh while continuing to display stale data - [Controller.fetch](#fetch).
166206
167207:::
168208
@@ -176,7 +216,7 @@ For REST try using [Resource.delete](/rest/api/createResource#delete)
176216// deletes MyResource(5)
177217// this will resuspend MyResource.get({ id : ' 5' } )
178218// and remove it from MyResource.getList
179- controller.setResponse(MyResource.delete, { id : ' 5' } , { id : ' 5' } )
219+ controller.setResponse(MyResource.delete, { id : ' 5' } , { id : ' 5' } );
180220```
181221
182222:::
@@ -199,6 +239,12 @@ function ArticleName({ id }: { id: string }) {
199239}
200240```
201241
242+ :::tip
243+
244+ To refresh while continuing to display stale data - [Controller.expireAll](#expireAll) instead.
245+
246+ :::
247+
202248Here we clear only GET endpoints using the test.com domain. This means other domains remain in cache.
203249
204250```tsx
@@ -227,7 +273,7 @@ const managers = [
227273 // call custom unAuth function we defined
228274 unAuth();
229275 // still reset the store
230- controller.invalidateAll({ testKey })
276+ controller.invalidateAll({ testKey });
231277 },
232278 } ),
233279 ...CacheProvider.defaultProps.managers,
@@ -240,7 +286,6 @@ ReactDOM.createRoot(document.body).render(
240286);
241287```
242288
243-
244289## resetEntireStore() { #resetEntireStore }
245290
246291Resets/clears the entire Reactive Data Client cache. All inflight requests will not resolve.
0 commit comments