@isdk/proxy 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.cn.md +138 -0
- package/README.md +129 -0
- package/dist/index.d.mts +213 -0
- package/dist/index.d.ts +213 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/docs/README.md +133 -0
- package/docs/classes/SmartCache.md +148 -0
- package/docs/functions/createCachedFetch.md +52 -0
- package/docs/functions/createFetchWithCache.md +52 -0
- package/docs/functions/extractData.md +39 -0
- package/docs/functions/fetchWithCache.md +39 -0
- package/docs/functions/generateCacheKey.md +27 -0
- package/docs/functions/isAllowed.md +38 -0
- package/docs/globals.md +29 -0
- package/docs/interfaces/CacheEntry.md +123 -0
- package/docs/interfaces/CacheMetadata.md +88 -0
- package/docs/interfaces/FetchWithCacheContext.md +161 -0
- package/docs/interfaces/FetchWithCacheOptions.md +103 -0
- package/docs/interfaces/KeyFilterConfig.md +33 -0
- package/docs/interfaces/ProxyConfig.md +41 -0
- package/docs/interfaces/SiteCacheConfig.md +61 -0
- package/docs/interfaces/SmartCacheOptions.md +41 -0
- package/package.json +101 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / fetchWithCache
|
|
6
|
+
|
|
7
|
+
# Function: fetchWithCache()
|
|
8
|
+
|
|
9
|
+
> **fetchWithCache**(`request`, `fetcher`, `options`): `Promise`\<`Response`\>
|
|
10
|
+
|
|
11
|
+
Defined in: [core/fetchWithCache.ts:244](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L244)
|
|
12
|
+
|
|
13
|
+
核心协调函数 (Fetcher Orchestrator)
|
|
14
|
+
|
|
15
|
+
实现了基于流的混合缓存代理核心逻辑,主要机制包括:
|
|
16
|
+
- **大文件流式处理**:底层完全通过 Streams 实现,代理大文件时自动写入磁盘且防 OOM。
|
|
17
|
+
- **SWR (Stale-While-Revalidate)**:后台静默更新机制。
|
|
18
|
+
- **并发防击穿 (Request Coalescing)**:利用 `activeCacheWrites` 将并发请求合并。
|
|
19
|
+
- **强制离线容灾**:支持 `staleIfError` 和 `forceCache`(无视 Cache-Control 强制入库)。
|
|
20
|
+
|
|
21
|
+
并且会在响应头中自动注入 `x-proxy-cache` 标明缓存命中状态 (`HIT`, `STALE`, `MISS`, `STALE_IF_ERROR`)。
|
|
22
|
+
|
|
23
|
+
## Parameters
|
|
24
|
+
|
|
25
|
+
### request
|
|
26
|
+
|
|
27
|
+
`Request`
|
|
28
|
+
|
|
29
|
+
### fetcher
|
|
30
|
+
|
|
31
|
+
(`req`) => `Promise`\<`Response`\>
|
|
32
|
+
|
|
33
|
+
### options
|
|
34
|
+
|
|
35
|
+
[`FetchWithCacheOptions`](../interfaces/FetchWithCacheOptions.md)
|
|
36
|
+
|
|
37
|
+
## Returns
|
|
38
|
+
|
|
39
|
+
`Promise`\<`Response`\>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / generateCacheKey
|
|
6
|
+
|
|
7
|
+
# Function: generateCacheKey()
|
|
8
|
+
|
|
9
|
+
> **generateCacheKey**(`req`, `config`): `string`
|
|
10
|
+
|
|
11
|
+
Defined in: [core/generateCacheKey.ts:8](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/generateCacheKey.ts#L8)
|
|
12
|
+
|
|
13
|
+
根据 Request 和配置生成唯一的缓存键
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### req
|
|
18
|
+
|
|
19
|
+
`Request`
|
|
20
|
+
|
|
21
|
+
### config
|
|
22
|
+
|
|
23
|
+
[`SiteCacheConfig`](../interfaces/SiteCacheConfig.md)
|
|
24
|
+
|
|
25
|
+
## Returns
|
|
26
|
+
|
|
27
|
+
`string`
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / isAllowed
|
|
6
|
+
|
|
7
|
+
# Function: isAllowed()
|
|
8
|
+
|
|
9
|
+
> **isAllowed**(`key`, `config?`): `boolean`
|
|
10
|
+
|
|
11
|
+
Defined in: [utils/isAllowed.ts:15](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/utils/isAllowed.ts#L15)
|
|
12
|
+
|
|
13
|
+
判断给定的键是否允许参与缓存指纹计算。
|
|
14
|
+
|
|
15
|
+
优先级逻辑:
|
|
16
|
+
1. 如果配置了 `include` (白名单),则只有存在于 `include` 中的键才会被允许。
|
|
17
|
+
2. 否则,如果配置了 `exclude` (黑名单),则存在于 `exclude` 中的键将被拒绝。
|
|
18
|
+
3. 如果都没有配置,默认允许所有键。
|
|
19
|
+
|
|
20
|
+
## Parameters
|
|
21
|
+
|
|
22
|
+
### key
|
|
23
|
+
|
|
24
|
+
`string`
|
|
25
|
+
|
|
26
|
+
要检查的键名
|
|
27
|
+
|
|
28
|
+
### config?
|
|
29
|
+
|
|
30
|
+
[`KeyFilterConfig`](../interfaces/KeyFilterConfig.md)
|
|
31
|
+
|
|
32
|
+
过滤配置
|
|
33
|
+
|
|
34
|
+
## Returns
|
|
35
|
+
|
|
36
|
+
`boolean`
|
|
37
|
+
|
|
38
|
+
是否允许
|
package/docs/globals.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[**@isdk/proxy**](README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# @isdk/proxy
|
|
6
|
+
|
|
7
|
+
## Classes
|
|
8
|
+
|
|
9
|
+
- [SmartCache](classes/SmartCache.md)
|
|
10
|
+
|
|
11
|
+
## Interfaces
|
|
12
|
+
|
|
13
|
+
- [CacheEntry](interfaces/CacheEntry.md)
|
|
14
|
+
- [CacheMetadata](interfaces/CacheMetadata.md)
|
|
15
|
+
- [FetchWithCacheContext](interfaces/FetchWithCacheContext.md)
|
|
16
|
+
- [FetchWithCacheOptions](interfaces/FetchWithCacheOptions.md)
|
|
17
|
+
- [KeyFilterConfig](interfaces/KeyFilterConfig.md)
|
|
18
|
+
- [ProxyConfig](interfaces/ProxyConfig.md)
|
|
19
|
+
- [SiteCacheConfig](interfaces/SiteCacheConfig.md)
|
|
20
|
+
- [SmartCacheOptions](interfaces/SmartCacheOptions.md)
|
|
21
|
+
|
|
22
|
+
## Functions
|
|
23
|
+
|
|
24
|
+
- [createCachedFetch](functions/createCachedFetch.md)
|
|
25
|
+
- [createFetchWithCache](functions/createFetchWithCache.md)
|
|
26
|
+
- [extractData](functions/extractData.md)
|
|
27
|
+
- [fetchWithCache](functions/fetchWithCache.md)
|
|
28
|
+
- [generateCacheKey](functions/generateCacheKey.md)
|
|
29
|
+
- [isAllowed](functions/isAllowed.md)
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / CacheEntry
|
|
6
|
+
|
|
7
|
+
# Interface: CacheEntry
|
|
8
|
+
|
|
9
|
+
Defined in: [types.ts:55](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L55)
|
|
10
|
+
|
|
11
|
+
完整的缓存条目
|
|
12
|
+
|
|
13
|
+
## Extends
|
|
14
|
+
|
|
15
|
+
- [`CacheMetadata`](CacheMetadata.md)
|
|
16
|
+
|
|
17
|
+
## Properties
|
|
18
|
+
|
|
19
|
+
### body
|
|
20
|
+
|
|
21
|
+
> **body**: `any`
|
|
22
|
+
|
|
23
|
+
Defined in: [types.ts:57](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L57)
|
|
24
|
+
|
|
25
|
+
响应体数据:小文件为 Buffer,大文件为可读流
|
|
26
|
+
|
|
27
|
+
***
|
|
28
|
+
|
|
29
|
+
### headers
|
|
30
|
+
|
|
31
|
+
> **headers**: `Record`\<`string`, `string`\>
|
|
32
|
+
|
|
33
|
+
Defined in: [types.ts:39](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L39)
|
|
34
|
+
|
|
35
|
+
响应头对象
|
|
36
|
+
|
|
37
|
+
#### Inherited from
|
|
38
|
+
|
|
39
|
+
[`CacheMetadata`](CacheMetadata.md).[`headers`](CacheMetadata.md#headers)
|
|
40
|
+
|
|
41
|
+
***
|
|
42
|
+
|
|
43
|
+
### method
|
|
44
|
+
|
|
45
|
+
> **method**: `string`
|
|
46
|
+
|
|
47
|
+
Defined in: [types.ts:45](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L45)
|
|
48
|
+
|
|
49
|
+
原始请求方法
|
|
50
|
+
|
|
51
|
+
#### Inherited from
|
|
52
|
+
|
|
53
|
+
[`CacheMetadata`](CacheMetadata.md).[`method`](CacheMetadata.md#method)
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
### policy
|
|
58
|
+
|
|
59
|
+
> **policy**: `any`
|
|
60
|
+
|
|
61
|
+
Defined in: [types.ts:41](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L41)
|
|
62
|
+
|
|
63
|
+
http-cache-semantics 策略对象,包含 TTL 和缓存指令
|
|
64
|
+
|
|
65
|
+
#### Inherited from
|
|
66
|
+
|
|
67
|
+
[`CacheMetadata`](CacheMetadata.md).[`policy`](CacheMetadata.md#policy)
|
|
68
|
+
|
|
69
|
+
***
|
|
70
|
+
|
|
71
|
+
### size
|
|
72
|
+
|
|
73
|
+
> **size**: `number`
|
|
74
|
+
|
|
75
|
+
Defined in: [types.ts:49](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L49)
|
|
76
|
+
|
|
77
|
+
Body 的字节长度,用于精确区分“空响应”与“未入内存的大响应”
|
|
78
|
+
|
|
79
|
+
#### Inherited from
|
|
80
|
+
|
|
81
|
+
[`CacheMetadata`](CacheMetadata.md).[`size`](CacheMetadata.md#size)
|
|
82
|
+
|
|
83
|
+
***
|
|
84
|
+
|
|
85
|
+
### status
|
|
86
|
+
|
|
87
|
+
> **status**: `number`
|
|
88
|
+
|
|
89
|
+
Defined in: [types.ts:37](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L37)
|
|
90
|
+
|
|
91
|
+
HTTP 状态码
|
|
92
|
+
|
|
93
|
+
#### Inherited from
|
|
94
|
+
|
|
95
|
+
[`CacheMetadata`](CacheMetadata.md).[`status`](CacheMetadata.md#status)
|
|
96
|
+
|
|
97
|
+
***
|
|
98
|
+
|
|
99
|
+
### timestamp
|
|
100
|
+
|
|
101
|
+
> **timestamp**: `number`
|
|
102
|
+
|
|
103
|
+
Defined in: [types.ts:47](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L47)
|
|
104
|
+
|
|
105
|
+
缓存写入时的时间戳
|
|
106
|
+
|
|
107
|
+
#### Inherited from
|
|
108
|
+
|
|
109
|
+
[`CacheMetadata`](CacheMetadata.md).[`timestamp`](CacheMetadata.md#timestamp)
|
|
110
|
+
|
|
111
|
+
***
|
|
112
|
+
|
|
113
|
+
### url
|
|
114
|
+
|
|
115
|
+
> **url**: `string`
|
|
116
|
+
|
|
117
|
+
Defined in: [types.ts:43](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L43)
|
|
118
|
+
|
|
119
|
+
原始请求 URL
|
|
120
|
+
|
|
121
|
+
#### Inherited from
|
|
122
|
+
|
|
123
|
+
[`CacheMetadata`](CacheMetadata.md).[`url`](CacheMetadata.md#url)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / CacheMetadata
|
|
6
|
+
|
|
7
|
+
# Interface: CacheMetadata
|
|
8
|
+
|
|
9
|
+
Defined in: [types.ts:35](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L35)
|
|
10
|
+
|
|
11
|
+
缓存元数据
|
|
12
|
+
|
|
13
|
+
存储在 L1 内存和 L2 磁盘中的非 Body 信息。
|
|
14
|
+
即使 Body 过大未进入内存,此元数据也会驻留在内存中以供快速策略判定。
|
|
15
|
+
|
|
16
|
+
## Extended by
|
|
17
|
+
|
|
18
|
+
- [`CacheEntry`](CacheEntry.md)
|
|
19
|
+
|
|
20
|
+
## Properties
|
|
21
|
+
|
|
22
|
+
### headers
|
|
23
|
+
|
|
24
|
+
> **headers**: `Record`\<`string`, `string`\>
|
|
25
|
+
|
|
26
|
+
Defined in: [types.ts:39](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L39)
|
|
27
|
+
|
|
28
|
+
响应头对象
|
|
29
|
+
|
|
30
|
+
***
|
|
31
|
+
|
|
32
|
+
### method
|
|
33
|
+
|
|
34
|
+
> **method**: `string`
|
|
35
|
+
|
|
36
|
+
Defined in: [types.ts:45](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L45)
|
|
37
|
+
|
|
38
|
+
原始请求方法
|
|
39
|
+
|
|
40
|
+
***
|
|
41
|
+
|
|
42
|
+
### policy
|
|
43
|
+
|
|
44
|
+
> **policy**: `any`
|
|
45
|
+
|
|
46
|
+
Defined in: [types.ts:41](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L41)
|
|
47
|
+
|
|
48
|
+
http-cache-semantics 策略对象,包含 TTL 和缓存指令
|
|
49
|
+
|
|
50
|
+
***
|
|
51
|
+
|
|
52
|
+
### size
|
|
53
|
+
|
|
54
|
+
> **size**: `number`
|
|
55
|
+
|
|
56
|
+
Defined in: [types.ts:49](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L49)
|
|
57
|
+
|
|
58
|
+
Body 的字节长度,用于精确区分“空响应”与“未入内存的大响应”
|
|
59
|
+
|
|
60
|
+
***
|
|
61
|
+
|
|
62
|
+
### status
|
|
63
|
+
|
|
64
|
+
> **status**: `number`
|
|
65
|
+
|
|
66
|
+
Defined in: [types.ts:37](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L37)
|
|
67
|
+
|
|
68
|
+
HTTP 状态码
|
|
69
|
+
|
|
70
|
+
***
|
|
71
|
+
|
|
72
|
+
### timestamp
|
|
73
|
+
|
|
74
|
+
> **timestamp**: `number`
|
|
75
|
+
|
|
76
|
+
Defined in: [types.ts:47](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L47)
|
|
77
|
+
|
|
78
|
+
缓存写入时的时间戳
|
|
79
|
+
|
|
80
|
+
***
|
|
81
|
+
|
|
82
|
+
### url
|
|
83
|
+
|
|
84
|
+
> **url**: `string`
|
|
85
|
+
|
|
86
|
+
Defined in: [types.ts:43](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L43)
|
|
87
|
+
|
|
88
|
+
原始请求 URL
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / FetchWithCacheContext
|
|
6
|
+
|
|
7
|
+
# Interface: FetchWithCacheContext
|
|
8
|
+
|
|
9
|
+
Defined in: [core/fetchWithCache.ts:31](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L31)
|
|
10
|
+
|
|
11
|
+
内部流水线上下文,合并了入参和计算出的关键状态
|
|
12
|
+
|
|
13
|
+
## Extends
|
|
14
|
+
|
|
15
|
+
- [`FetchWithCacheOptions`](FetchWithCacheOptions.md)
|
|
16
|
+
|
|
17
|
+
## Properties
|
|
18
|
+
|
|
19
|
+
### activeCacheWrites
|
|
20
|
+
|
|
21
|
+
> **activeCacheWrites**: `Map`\<`string`, `Promise`\<`void`\>\>
|
|
22
|
+
|
|
23
|
+
Defined in: [core/fetchWithCache.ts:35](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L35)
|
|
24
|
+
|
|
25
|
+
并发写入任务追踪器
|
|
26
|
+
传入一个外部维护的 Map,用于在跨请求、跨实例时防止针对同一文件的并发重复下载。
|
|
27
|
+
Map 的 Key 是缓存 Key,Value 是一个代表写入完成的 Promise。
|
|
28
|
+
|
|
29
|
+
#### Overrides
|
|
30
|
+
|
|
31
|
+
[`FetchWithCacheOptions`](FetchWithCacheOptions.md).[`activeCacheWrites`](FetchWithCacheOptions.md#activecachewrites)
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
35
|
+
### backgroundUpdate?
|
|
36
|
+
|
|
37
|
+
> `optional` **backgroundUpdate**: `boolean`
|
|
38
|
+
|
|
39
|
+
Defined in: [core/fetchWithCache.ts:17](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L17)
|
|
40
|
+
|
|
41
|
+
是否启用后台异步更新 (SWR)
|
|
42
|
+
|
|
43
|
+
#### Inherited from
|
|
44
|
+
|
|
45
|
+
[`FetchWithCacheOptions`](FetchWithCacheOptions.md).[`backgroundUpdate`](FetchWithCacheOptions.md#backgroundupdate)
|
|
46
|
+
|
|
47
|
+
***
|
|
48
|
+
|
|
49
|
+
### cache
|
|
50
|
+
|
|
51
|
+
> **cache**: [`SmartCache`](../classes/SmartCache.md)
|
|
52
|
+
|
|
53
|
+
Defined in: [core/fetchWithCache.ts:13](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L13)
|
|
54
|
+
|
|
55
|
+
混合缓存实例
|
|
56
|
+
|
|
57
|
+
#### Inherited from
|
|
58
|
+
|
|
59
|
+
[`FetchWithCacheOptions`](FetchWithCacheOptions.md).[`cache`](FetchWithCacheOptions.md#cache)
|
|
60
|
+
|
|
61
|
+
***
|
|
62
|
+
|
|
63
|
+
### cacheKey
|
|
64
|
+
|
|
65
|
+
> **cacheKey**: `string`
|
|
66
|
+
|
|
67
|
+
Defined in: [core/fetchWithCache.ts:34](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L34)
|
|
68
|
+
|
|
69
|
+
***
|
|
70
|
+
|
|
71
|
+
### config
|
|
72
|
+
|
|
73
|
+
> **config**: [`SiteCacheConfig`](SiteCacheConfig.md)
|
|
74
|
+
|
|
75
|
+
Defined in: [core/fetchWithCache.ts:15](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L15)
|
|
76
|
+
|
|
77
|
+
站点级缓存配置
|
|
78
|
+
|
|
79
|
+
#### Inherited from
|
|
80
|
+
|
|
81
|
+
[`FetchWithCacheOptions`](FetchWithCacheOptions.md).[`config`](FetchWithCacheOptions.md#config)
|
|
82
|
+
|
|
83
|
+
***
|
|
84
|
+
|
|
85
|
+
### fetcher()
|
|
86
|
+
|
|
87
|
+
> **fetcher**: (`req`) => `Promise`\<`Response`\>
|
|
88
|
+
|
|
89
|
+
Defined in: [core/fetchWithCache.ts:33](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L33)
|
|
90
|
+
|
|
91
|
+
#### Parameters
|
|
92
|
+
|
|
93
|
+
##### req
|
|
94
|
+
|
|
95
|
+
`Request`
|
|
96
|
+
|
|
97
|
+
#### Returns
|
|
98
|
+
|
|
99
|
+
`Promise`\<`Response`\>
|
|
100
|
+
|
|
101
|
+
***
|
|
102
|
+
|
|
103
|
+
### generateKey()?
|
|
104
|
+
|
|
105
|
+
> `optional` **generateKey**: (`req`, `config`) => `string`
|
|
106
|
+
|
|
107
|
+
Defined in: [core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L21)
|
|
108
|
+
|
|
109
|
+
自定义缓存键生成函数
|
|
110
|
+
|
|
111
|
+
根据 Request 和配置生成唯一的缓存键
|
|
112
|
+
|
|
113
|
+
#### Parameters
|
|
114
|
+
|
|
115
|
+
##### req
|
|
116
|
+
|
|
117
|
+
`Request`
|
|
118
|
+
|
|
119
|
+
##### config
|
|
120
|
+
|
|
121
|
+
[`SiteCacheConfig`](SiteCacheConfig.md)
|
|
122
|
+
|
|
123
|
+
#### Returns
|
|
124
|
+
|
|
125
|
+
`string`
|
|
126
|
+
|
|
127
|
+
#### Inherited from
|
|
128
|
+
|
|
129
|
+
[`FetchWithCacheOptions`](FetchWithCacheOptions.md).[`generateKey`](FetchWithCacheOptions.md#generatekey)
|
|
130
|
+
|
|
131
|
+
***
|
|
132
|
+
|
|
133
|
+
### onBackgroundUpdate()?
|
|
134
|
+
|
|
135
|
+
> `optional` **onBackgroundUpdate**: (`promise`) => `void`
|
|
136
|
+
|
|
137
|
+
Defined in: [core/fetchWithCache.ts:19](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L19)
|
|
138
|
+
|
|
139
|
+
后台更新 Promise 触发时的回调
|
|
140
|
+
|
|
141
|
+
#### Parameters
|
|
142
|
+
|
|
143
|
+
##### promise
|
|
144
|
+
|
|
145
|
+
`Promise`\<`Response`\>
|
|
146
|
+
|
|
147
|
+
#### Returns
|
|
148
|
+
|
|
149
|
+
`void`
|
|
150
|
+
|
|
151
|
+
#### Inherited from
|
|
152
|
+
|
|
153
|
+
[`FetchWithCacheOptions`](FetchWithCacheOptions.md).[`onBackgroundUpdate`](FetchWithCacheOptions.md#onbackgroundupdate)
|
|
154
|
+
|
|
155
|
+
***
|
|
156
|
+
|
|
157
|
+
### request
|
|
158
|
+
|
|
159
|
+
> **request**: `Request`
|
|
160
|
+
|
|
161
|
+
Defined in: [core/fetchWithCache.ts:32](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L32)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / FetchWithCacheOptions
|
|
6
|
+
|
|
7
|
+
# Interface: FetchWithCacheOptions
|
|
8
|
+
|
|
9
|
+
Defined in: [core/fetchWithCache.ts:11](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L11)
|
|
10
|
+
|
|
11
|
+
fetchWithCache 选项
|
|
12
|
+
|
|
13
|
+
## Extended by
|
|
14
|
+
|
|
15
|
+
- [`FetchWithCacheContext`](FetchWithCacheContext.md)
|
|
16
|
+
|
|
17
|
+
## Properties
|
|
18
|
+
|
|
19
|
+
### activeCacheWrites?
|
|
20
|
+
|
|
21
|
+
> `optional` **activeCacheWrites**: `Map`\<`string`, `Promise`\<`void`\>\>
|
|
22
|
+
|
|
23
|
+
Defined in: [core/fetchWithCache.ts:27](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L27)
|
|
24
|
+
|
|
25
|
+
并发写入任务追踪器
|
|
26
|
+
传入一个外部维护的 Map,用于在跨请求、跨实例时防止针对同一文件的并发重复下载。
|
|
27
|
+
Map 的 Key 是缓存 Key,Value 是一个代表写入完成的 Promise。
|
|
28
|
+
|
|
29
|
+
***
|
|
30
|
+
|
|
31
|
+
### backgroundUpdate?
|
|
32
|
+
|
|
33
|
+
> `optional` **backgroundUpdate**: `boolean`
|
|
34
|
+
|
|
35
|
+
Defined in: [core/fetchWithCache.ts:17](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L17)
|
|
36
|
+
|
|
37
|
+
是否启用后台异步更新 (SWR)
|
|
38
|
+
|
|
39
|
+
***
|
|
40
|
+
|
|
41
|
+
### cache
|
|
42
|
+
|
|
43
|
+
> **cache**: [`SmartCache`](../classes/SmartCache.md)
|
|
44
|
+
|
|
45
|
+
Defined in: [core/fetchWithCache.ts:13](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L13)
|
|
46
|
+
|
|
47
|
+
混合缓存实例
|
|
48
|
+
|
|
49
|
+
***
|
|
50
|
+
|
|
51
|
+
### config
|
|
52
|
+
|
|
53
|
+
> **config**: [`SiteCacheConfig`](SiteCacheConfig.md)
|
|
54
|
+
|
|
55
|
+
Defined in: [core/fetchWithCache.ts:15](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L15)
|
|
56
|
+
|
|
57
|
+
站点级缓存配置
|
|
58
|
+
|
|
59
|
+
***
|
|
60
|
+
|
|
61
|
+
### generateKey()?
|
|
62
|
+
|
|
63
|
+
> `optional` **generateKey**: (`req`, `config`) => `string`
|
|
64
|
+
|
|
65
|
+
Defined in: [core/fetchWithCache.ts:21](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L21)
|
|
66
|
+
|
|
67
|
+
自定义缓存键生成函数
|
|
68
|
+
|
|
69
|
+
根据 Request 和配置生成唯一的缓存键
|
|
70
|
+
|
|
71
|
+
#### Parameters
|
|
72
|
+
|
|
73
|
+
##### req
|
|
74
|
+
|
|
75
|
+
`Request`
|
|
76
|
+
|
|
77
|
+
##### config
|
|
78
|
+
|
|
79
|
+
[`SiteCacheConfig`](SiteCacheConfig.md)
|
|
80
|
+
|
|
81
|
+
#### Returns
|
|
82
|
+
|
|
83
|
+
`string`
|
|
84
|
+
|
|
85
|
+
***
|
|
86
|
+
|
|
87
|
+
### onBackgroundUpdate()?
|
|
88
|
+
|
|
89
|
+
> `optional` **onBackgroundUpdate**: (`promise`) => `void`
|
|
90
|
+
|
|
91
|
+
Defined in: [core/fetchWithCache.ts:19](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/core/fetchWithCache.ts#L19)
|
|
92
|
+
|
|
93
|
+
后台更新 Promise 触发时的回调
|
|
94
|
+
|
|
95
|
+
#### Parameters
|
|
96
|
+
|
|
97
|
+
##### promise
|
|
98
|
+
|
|
99
|
+
`Promise`\<`Response`\>
|
|
100
|
+
|
|
101
|
+
#### Returns
|
|
102
|
+
|
|
103
|
+
`void`
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / KeyFilterConfig
|
|
6
|
+
|
|
7
|
+
# Interface: KeyFilterConfig
|
|
8
|
+
|
|
9
|
+
Defined in: [types.ts:6](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L6)
|
|
10
|
+
|
|
11
|
+
缓存键过滤配置
|
|
12
|
+
|
|
13
|
+
用于定义在生成缓存指纹时,哪些字段应该被包含或排除。
|
|
14
|
+
|
|
15
|
+
## Properties
|
|
16
|
+
|
|
17
|
+
### exclude?
|
|
18
|
+
|
|
19
|
+
> `optional` **exclude**: `string`[]
|
|
20
|
+
|
|
21
|
+
Defined in: [types.ts:10](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L10)
|
|
22
|
+
|
|
23
|
+
排除(黑名单):用于排除像 `timestamp`、`nonce` 等干扰缓存命中的动态字段
|
|
24
|
+
|
|
25
|
+
***
|
|
26
|
+
|
|
27
|
+
### include?
|
|
28
|
+
|
|
29
|
+
> `optional` **include**: `string`[]
|
|
30
|
+
|
|
31
|
+
Defined in: [types.ts:8](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L8)
|
|
32
|
+
|
|
33
|
+
仅包含(白名单):如果设置,只有这些字段会参与 Key 的计算
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
[**@isdk/proxy**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@isdk/proxy](../globals.md) / ProxyConfig
|
|
6
|
+
|
|
7
|
+
# Interface: ProxyConfig
|
|
8
|
+
|
|
9
|
+
Defined in: [types.ts:63](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L63)
|
|
10
|
+
|
|
11
|
+
代理拦截器全局配置
|
|
12
|
+
|
|
13
|
+
## Properties
|
|
14
|
+
|
|
15
|
+
### default
|
|
16
|
+
|
|
17
|
+
> **default**: [`SiteCacheConfig`](SiteCacheConfig.md)
|
|
18
|
+
|
|
19
|
+
Defined in: [types.ts:65](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L65)
|
|
20
|
+
|
|
21
|
+
默认缓存配置,当请求的域名未在 sites 中匹配时使用
|
|
22
|
+
|
|
23
|
+
***
|
|
24
|
+
|
|
25
|
+
### sites
|
|
26
|
+
|
|
27
|
+
> **sites**: `Record`\<`string`, [`SiteCacheConfig`](SiteCacheConfig.md)\>
|
|
28
|
+
|
|
29
|
+
Defined in: [types.ts:67](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L67)
|
|
30
|
+
|
|
31
|
+
针对特定域名的精细化缓存配置
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
35
|
+
### storagePath?
|
|
36
|
+
|
|
37
|
+
> `optional` **storagePath**: `string`
|
|
38
|
+
|
|
39
|
+
Defined in: [types.ts:69](https://github.com/isdk/proxy.js/blob/bed37fa43507dcbe5cdfa453876163571399d761/src/types.ts#L69)
|
|
40
|
+
|
|
41
|
+
磁盘缓存(cacache)的物理存储路径,可选,默认为系统临时目录
|