You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -427,30 +427,30 @@ The return value of the `preload` function is passed to the page component when
427
427
428
428
Keep in mind these are completely optional. To use but showcase the power of our preload mechanism.
429
429
430
-
### `cache`
430
+
### `query`
431
431
432
-
To prevent duplicate fetching and to trigger handle refetching we provide a cache api. That takes a function and returns the same function.
432
+
To prevent duplicate fetching and to trigger handle refetching we provide a query api. That takes a function and returns the same function.
433
433
434
434
```jsx
435
-
constgetUser=cache(async (id) => {
435
+
constgetUser=query(async (id) => {
436
436
return (awaitfetch(`/api/users${id}`)).json()
437
-
}, "users") // used as cache key + serialized arguments
437
+
}, "users") // used as the query key + serialized arguments
438
438
```
439
-
It is expected that the arguments to the cache function are serializable.
439
+
It is expected that the arguments to the query function are serializable.
440
440
441
-
This cache accomplishes the following:
441
+
This query accomplishes the following:
442
442
443
-
1. It does just deduping on the server for the lifetime of the request.
444
-
2. It does preload cache in the browser which lasts 5 seconds. When a route is preloaded on hover or when preload is called when entering a route it will make sure to dedupe calls.
443
+
1. It does deduping on the server for the lifetime of the request.
444
+
2. It fills a preload cache in the browser which lasts 5 seconds. When a route is preloaded on hover or when preload is called when entering a route it will make sure to dedupe calls.
445
445
3. We have a reactive refetch mechanism based on key. So we can tell routes that aren't new to retrigger on action revalidation.
446
-
4. It will serve as a back/forward cache for browser navigation up to 5 mins. Any user based navigation or link click bypasses it. Revalidation or new fetch updates the cache.
446
+
4. It will serve as a back/forward cache for browser navigation up to 5 mins. Any user based navigation or link click bypasses this cache. Revalidation or new fetch updates the cache.
You can revalidate the cache using the `revalidate` method or you can set `revalidate` keys on your response from your actions. If you pass the whole key it will invalidate all the entries for the cache (ie "users" in the example above). You can also invalidate a single entry by using `keyFor`.
486
+
You can revalidate the query using the `revalidate` method or you can set `revalidate` keys on your response from your actions. If you pass the whole key it will invalidate all the entries for the query (ie "users" in the example above). You can also invalidate a single entry by using `keyFor`.
487
487
488
-
`cache` can be defined anywhere and then used inside your components with:
488
+
`query` can be defined anywhere and then used inside your components with:
489
489
490
490
### `createAsync`
491
491
@@ -502,7 +502,7 @@ const user = createAsync((currentValue) => getUser(params.id))
502
502
return<h1>{user.latest.name}</h1>;
503
503
```
504
504
505
-
Using `cache` in `createResource` directly won't work properly as the fetcher is not reactive and it won't invalidate properly.
505
+
Using `query` in `createResource` directly won't work properly as the fetcher is not reactive and it won't invalidate properly.
These are used to communicate router navigations from cache/actions, and can include invalidation hints. Generally these are thrown to not interfere the with the types and make it clear that function ends execution at that point.
600
+
These are used to communicate router navigations from query/actions, and can include invalidation hints. Generally these are thrown to not interfere the with the types and make it clear that function ends execution at that point.
601
601
602
602
#### `redirect(path, options)`
603
603
604
604
Redirects to the next route
605
605
```js
606
-
constgetUser=cache(() => {
606
+
constgetUser=query(() => {
607
607
constuser=awaitapi.getCurrentUser()
608
608
if (!user) throwredirect("/login");
609
609
return user;
@@ -614,7 +614,7 @@ const getUser = cache(() => {
614
614
615
615
Reloads the data on the current page
616
616
```js
617
-
constgetTodo=cache(async (id:number) => {
617
+
constgetTodo=query(async (id:number) => {
618
618
consttodo=awaitfetchTodo(id);
619
619
return todo;
620
620
}, "todo")
@@ -937,7 +937,7 @@ Related without Outlet component it has to be passed in manually. At which point
937
937
938
938
### `data` functions & `useRouteData`
939
939
940
-
These have been replaced by a preload mechanism. This allows link hover preloads (as the preload function can be run as much as wanted without worry about reactivity). It support deduping/cache APIs which give more control over how things are cached. It also addresses TS issues with getting the right types in the Component without `typeof` checks.
940
+
These have been replaced by a preload mechanism. This allows link hover preloads (as the preload function can be run as much as wanted without worry about reactivity). It support deduping/query APIs which give more control over how things are cached. It also addresses TS issues with getting the right types in the Component without `typeof` checks.
941
941
942
942
That being said you can reproduce the old pattern largely by turning off preloads at the router level and then injecting your own Context:
0 commit comments