Skip to content

Commit 5b66237

Browse files
committed
docs: add cache doc
1 parent 6b53f65 commit 5b66237

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

packages/document/main-doc/docs/en/guides/basic-features/data/data-cache.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sidebar_position: 4
44
---
55
# Data Caching
66

7-
The `cache` function allows you to cache the results of data fetching or computation. It has all the capabilities of React's [cache](https://react.dev/reference/react/cache) function and can be used as a replacement, but it offers more powerful features.
7+
The `cache` function allows you to cache the results of data fetching or computation.
88

99
## Basic Usage
1010

@@ -55,7 +55,7 @@ EdenX's `cache` function can be used in any frontend or server-side code.
5555

5656
### Without `options` Parameter
5757

58-
When no `options` parameter is provided, it's primarily useful in SSR projects. For example, when the same cachedFn is called in multiple data loaders, the cachedFn function won't be executed repeatedly. This allows data sharing between different data loaders while avoiding duplicate requests. EdenX will re-execute the `fn` function with each server request (meaning the cache lifecycle is limited to a single SSR rendering request).
58+
When no `options` parameter is provided, it's primarily useful in SSR projects, the cache lifecycle is limited to a single SSR rendering request. For example, when the same cachedFn is called in multiple data loaders, the cachedFn function won't be executed repeatedly. This allows data sharing between different data loaders while avoiding duplicate requests. EdenX will re-execute the `fn` function with each server request.
5959

6060
:::info
6161
Without the `options` parameter, it can be considered a replacement for React's [`cache`](https://react.dev/reference/react/cache) function and can be used in any server-side code (such as in data loaders of SSR projects), not limited to server components.

packages/document/main-doc/docs/zh/guides/basic-features/data/data-cache.mdx

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ sidebar_position: 4
44
---
55
# 数据缓存
66

7-
`cache` 函数可以让你缓存数据获取或计算的结果,它拥有 react [cache](https://react.dev/reference/react/cache) 函数所有的能力,可以当做 `cache` 函数的替代品,
8-
但它的能力会比 `cache` 函数更强大。
7+
`cache` 函数可以让你缓存数据获取或计算的结果。
98

109
## 基本用法
1110

@@ -54,7 +53,7 @@ EdenX 提供的 `cache` 函数可以在任意的前端或服务端的代码中
5453

5554
### `options` 参数
5655

57-
当无 `options` 参数传入时,主要可以用于 SSR 项目,如可以在多个 data loader 中调用同一个 cachedFn 时,不会重复执行 cachedFn 函数。这样可以在不同的 data loader 中共享数据,同时避免重复的请求EdenX 会在每次收到服务端请求时,重新执行 `fn` 函数(即缓存的生命周期是单次 ssr 渲染的请求)
56+
当无 `options` 参数传入时,主要可以用于 SSR 项目,缓存的生命周期是单次 ssr 渲染的请求,如可以在多个 data loader 中调用同一个 cachedFn 时,不会重复执行 cachedFn 函数。这样可以在不同的 data loader 中共享数据,同时避免重复的请求EdenX 会在每次收到服务端请求时,重新执行 `fn` 函数。
5857

5958
:::info
6059
`options` 参数时,可以看作是 react [`cache`](https://react.dev/reference/react/cache) 函数的替代品,可以在任意服务端代码中使用(比如可以在 SSR 项目的 data loader 中),不局限于 server component。
@@ -99,7 +98,7 @@ const getDashboardStats = cache(
9998
`revalidate` 参数用于设置缓存过期后,重新验证缓存的时间窗口,可以和 `maxAge` 参数一起使用,类似与 HTTP Cache-Control 的 stale-while-revalidate 模式。
10099

101100

102-
如以下示例,在缓存未过期的 2 分钟内,如果调用 `getDashboardStats` 函数,会返回缓存的数据,如果缓存过期,2 分到3分钟内,收到的请求会先返回旧数据,然后后台会重新请求数据,并更新缓存。
101+
如以下示例,在缓存未过期的 2分钟内,如果调用 `getDashboardStats` 函数,会返回缓存的数据,如果缓存过期,2分到3分钟内,收到的请求会先返回旧数据,然后后台会重新请求数据,并更新缓存。
103102

104103
```ts
105104
import { cache, CacheTime } from '@modern-js/runtime/cache';

0 commit comments

Comments
 (0)