diff --git a/packages/hooks/src/useRequest/doc/cache/cache.en-US.md b/packages/hooks/src/useRequest/doc/cache/cache.en-US.md index d521283d6f..58dce1b057 100644 --- a/packages/hooks/src/useRequest/doc/cache/cache.en-US.md +++ b/packages/hooks/src/useRequest/doc/cache/cache.en-US.md @@ -29,10 +29,12 @@ By setting `staleTime`, we can specify the data retention time, during which tim ### Data sharing -The content of the same `cacheKey` is shared globally, which will bring the following features +> Note: If no new request is issued, the "Data sharing" will not be triggered. `cacheTime` and `staleTime` parameters will invalidate "Data sharing". [#2313](https://github.com/alibaba/hooks/issues/2313) -- Sharing request `Promise`, only one of the same `cacheKey` will initiate a request at the same time, and the subsequent ones will share the same request `Promise`. -- Data synchronization. At any time, when we change the content of one of the `cacheKey`, the content of the other `cacheKey` will be synchronized. +The content of the same `cacheKey` is shared globally, which will bring the following features: + +- Sharing request `Promise`: Only one of the same `cacheKey` will initiate a request at the same time, and the subsequent ones will share the same request `Promise`. +- Data synchronization: When a request is made by one `cacheKey`, the contents of other identical `cacheKey` will be synchronized accordingly. In the following example, the two components will only initiate one request during initialization. And the content of the two articles is always synchronized. @@ -77,7 +79,7 @@ interface CachedData { | Property | Description | Type | Default | | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | -------- | -| cacheKey | A unique ID of the request. If `cacheKey` is set, we will enable the caching mechanism. The data of the same `cacheKey` is globally synchronized. | `string` | - | +| cacheKey | A unique ID of the request. Data of the same `cacheKey` will synchronized globally (`cacheTime` and `staleTime` parameters will invalidate this mechanism, see demo: [Data sharing](#data-sharing)) | `string` | - | | cacheTime | | `number` | `300000` | | staleTime | | `number` | `0` | | setCache | | `(data: CachedData) => void;` | - | diff --git a/packages/hooks/src/useRequest/doc/cache/cache.zh-CN.md b/packages/hooks/src/useRequest/doc/cache/cache.zh-CN.md index d5bfc547ca..4ec3444abf 100644 --- a/packages/hooks/src/useRequest/doc/cache/cache.zh-CN.md +++ b/packages/hooks/src/useRequest/doc/cache/cache.zh-CN.md @@ -29,10 +29,12 @@ group: ### 数据共享 -同一个 `cacheKey` 的内容,在全局是共享的,这会带来以下几个特性 +> 注意:如果没有发起新请求,不会触发数据共享。`cacheTime`、`staleTime` 参数会使数据共享失效。[#2313](https://github.com/alibaba/hooks/issues/2313) -- 请求 `Promise` 共享,相同的 `cacheKey` 同时只会有一个在发起请求,后发起的会共用同一个请求 `Promise` -- 数据同步,任何时候,当我们改变其中某个 `cacheKey` 的内容时,其它相同 `cacheKey` 的内容均会同步 +同一个 `cacheKey` 的内容,在全局是共享的,这会带来以下几个特性: + +- 请求 `Promise` 共享:相同的 `cacheKey` 同时只会有一个在发起请求,后发起的会共用同一个请求 `Promise` +- 数据同步:当某个 `cacheKey` 发起请求时,其它相同 `cacheKey` 的内容均会随之同步 下面的示例中,初始化时,两个组件只会发起一个请求。并且两篇文章的内容永远是同步的。 @@ -77,7 +79,7 @@ interface CachedData { | 参数 | 说明 | 类型 | 默认值 | | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | -------- | -| cacheKey | 请求唯一标识。如果设置了 `cacheKey`,我们会启用缓存机制。同一个 `cacheKey` 的数据全局同步。 | `string` | - | +| cacheKey | 请求的唯一标识。相同 `cacheKey` 的数据全局同步(`cacheTime`、`staleTime` 参数会使该机制失效,见示例:[数据共享](#数据共享))。 | `string` | - | | cacheTime | | `number` | `300000` | | staleTime | | `number` | `0` | | setCache | | `(data: CachedData) => void;` | - |