@keq-request/cache 5.0.0-alpha.7 → 5.0.0-beta.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/CHANGELOG.md +322 -0
- package/dist/index.d.mts +354 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +353 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1271 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1237 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +14 -22
- package/tsdown.config.ts +12 -0
- package/jest.config.cts +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,327 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.0.0-beta.1
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 5f5bdd9: **BREAKING CHANGE:** Simplified KeqCacheStrategy interface.
|
|
8
|
+
- 5175097: **BREAKING CHANGE:** group all packages under the @keq-request scope
|
|
9
|
+
|
|
10
|
+
- keq-cache => @keq-request/cache
|
|
11
|
+
- keq-headers => @keq-request/headers
|
|
12
|
+
- keq-cli => @keq-request/cli
|
|
13
|
+
- keq-url => @keq-request/url
|
|
14
|
+
- keq-exception => @keq-request/exception
|
|
15
|
+
|
|
16
|
+
- 153244f: **BREAKING CHANGE:** `onNetworkResponse` has been removed, please use `.on('cache:update', callback)` instead.
|
|
17
|
+
- 0a04864: **Fix:** fix: update browser targets to chrome91/firefox90/safari15/edge91 to resolve esbuild 0.27 destructuring build errors.
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- 153244f: **Feat:** Add `onCacheGet`, `onCacheSet`, `onCacheRemove`, `onCacheEvict` and `onCacheExpired` hook for `MemoryStorage` and `IndexedDBStorage`.
|
|
22
|
+
- 54520a9: **Feat:** using `.option('cache', false)` can disable caching for request that are cached by default
|
|
23
|
+
- 153244f: **Feat:** Add `cache:hit`, `cache:miss` and `cache:update` to keq events.
|
|
24
|
+
- 25414cb: add print method to display MemoryStorage entries
|
|
25
|
+
- 89274bd: **Feat:** add a Size enum make it easier to set the size
|
|
26
|
+
- d1090d3: **Feat:** add debug logs and Server-Timing header.
|
|
27
|
+
- 9ab2c64: Convert non-essential cli tasks into plugins.
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- b8d68c7: **Fix:** IndexedDBStorage cannot evict ttl cache
|
|
32
|
+
- bbfda6b: Fix the error throw when set server-timing header.
|
|
33
|
+
- 20c7067: **Fix:** Failed to automatically clean up expired cache data when get immediately after initialization.
|
|
34
|
+
- 153244f: **Feat:** `pattern` accept boolean and defaults to true
|
|
35
|
+
- 5d2ce07: **Perf:** add blocking for concurrent requests with same cache key.
|
|
36
|
+
- 2686b8d: build with turbo
|
|
37
|
+
- 153244f: **Fix:** unable to cache modified `ctx.res`.
|
|
38
|
+
- 2686b8d: remove private dependencies
|
|
39
|
+
- 9a9caa4: Cannot call CacheEntry.response.json multiple times.
|
|
40
|
+
- e7eb9dc: Don't publish .turbo and jest.config.cts to npm
|
|
41
|
+
- 0873c7e: Incorrect build before release.
|
|
42
|
+
- ff5464b: Prevent other middlewares from inadvertently modifying the cache key.
|
|
43
|
+
- 581815a: ensure compatibility
|
|
44
|
+
- 7343445: Incorrect build before release
|
|
45
|
+
- Updated dependencies [cbc5d17]
|
|
46
|
+
- Updated dependencies [153244f]
|
|
47
|
+
- Updated dependencies [153244f]
|
|
48
|
+
- Updated dependencies [153244f]
|
|
49
|
+
- Updated dependencies [0a2eb2f]
|
|
50
|
+
- Updated dependencies [153244f]
|
|
51
|
+
- Updated dependencies [214ae66]
|
|
52
|
+
- Updated dependencies [c7ffd1f]
|
|
53
|
+
- Updated dependencies [90311b3]
|
|
54
|
+
- Updated dependencies [1f367c0]
|
|
55
|
+
- Updated dependencies [0c7db81]
|
|
56
|
+
- Updated dependencies [df114d1]
|
|
57
|
+
- Updated dependencies [2686b8d]
|
|
58
|
+
- Updated dependencies [842e555]
|
|
59
|
+
- Updated dependencies [153244f]
|
|
60
|
+
- Updated dependencies [2686b8d]
|
|
61
|
+
- Updated dependencies [9290139]
|
|
62
|
+
- Updated dependencies [7873a0a]
|
|
63
|
+
- Updated dependencies [e7eb9dc]
|
|
64
|
+
- Updated dependencies [7ff2162]
|
|
65
|
+
- Updated dependencies [22ce01a]
|
|
66
|
+
- Updated dependencies [0873c7e]
|
|
67
|
+
- Updated dependencies [153244f]
|
|
68
|
+
- Updated dependencies [a7a83da]
|
|
69
|
+
- Updated dependencies [f194c41]
|
|
70
|
+
- Updated dependencies [153244f]
|
|
71
|
+
- Updated dependencies [153244f]
|
|
72
|
+
- Updated dependencies [d076b76]
|
|
73
|
+
- Updated dependencies [f8abc63]
|
|
74
|
+
- Updated dependencies [153244f]
|
|
75
|
+
- Updated dependencies [ca6c879]
|
|
76
|
+
- Updated dependencies [63161c4]
|
|
77
|
+
- Updated dependencies [d472648]
|
|
78
|
+
- Updated dependencies [b8d02ca]
|
|
79
|
+
- Updated dependencies [0a04864]
|
|
80
|
+
- Updated dependencies [581815a]
|
|
81
|
+
- Updated dependencies [7343445]
|
|
82
|
+
- Updated dependencies [153244f]
|
|
83
|
+
- Updated dependencies [eed26f9]
|
|
84
|
+
- keq@5.0.0-beta.1
|
|
85
|
+
|
|
86
|
+
## 5.0.0-alpha.36
|
|
87
|
+
|
|
88
|
+
### Patch Changes
|
|
89
|
+
|
|
90
|
+
- keq@5.0.0-alpha.36
|
|
91
|
+
|
|
92
|
+
## 5.0.0-alpha.35
|
|
93
|
+
|
|
94
|
+
### Major Changes
|
|
95
|
+
|
|
96
|
+
- 0a04864: **Fix:** fix: update browser targets to chrome91/firefox90/safari15/edge91 to resolve esbuild 0.27 destructuring build errors.
|
|
97
|
+
|
|
98
|
+
### Patch Changes
|
|
99
|
+
|
|
100
|
+
- Updated dependencies [0a04864]
|
|
101
|
+
- keq@5.0.0-alpha.35
|
|
102
|
+
|
|
103
|
+
## 5.0.0-alpha.34
|
|
104
|
+
|
|
105
|
+
### Patch Changes
|
|
106
|
+
|
|
107
|
+
- Updated dependencies [a7a83da]
|
|
108
|
+
- Updated dependencies [f8abc63]
|
|
109
|
+
- keq@5.0.0-alpha.34
|
|
110
|
+
|
|
111
|
+
## 5.0.0-alpha.33
|
|
112
|
+
|
|
113
|
+
### Patch Changes
|
|
114
|
+
|
|
115
|
+
- keq@5.0.0-alpha.33
|
|
116
|
+
|
|
117
|
+
## 5.0.0-alpha.32
|
|
118
|
+
|
|
119
|
+
### Patch Changes
|
|
120
|
+
|
|
121
|
+
- Updated dependencies [f194c41]
|
|
122
|
+
- Updated dependencies [b8d02ca]
|
|
123
|
+
- keq@5.0.0-alpha.32
|
|
124
|
+
|
|
125
|
+
## 5.0.0-alpha.31
|
|
126
|
+
|
|
127
|
+
### Patch Changes
|
|
128
|
+
|
|
129
|
+
- keq@5.0.0-alpha.31
|
|
130
|
+
|
|
131
|
+
## 5.0.0-alpha.30
|
|
132
|
+
|
|
133
|
+
### Patch Changes
|
|
134
|
+
|
|
135
|
+
- keq@5.0.0-alpha.30
|
|
136
|
+
|
|
137
|
+
## 5.0.0-alpha.29
|
|
138
|
+
|
|
139
|
+
### Patch Changes
|
|
140
|
+
|
|
141
|
+
- ff5464b: Prevent other middlewares from inadvertently modifying the cache key.
|
|
142
|
+
- keq@5.0.0-alpha.29
|
|
143
|
+
|
|
144
|
+
## 5.0.0-alpha.28
|
|
145
|
+
|
|
146
|
+
### Patch Changes
|
|
147
|
+
|
|
148
|
+
- Updated dependencies [d076b76]
|
|
149
|
+
- keq@5.0.0-alpha.28
|
|
150
|
+
|
|
151
|
+
## 5.0.0-alpha.27
|
|
152
|
+
|
|
153
|
+
### Patch Changes
|
|
154
|
+
|
|
155
|
+
- bbfda6b: Fix the error throw when set server-timing header.
|
|
156
|
+
- 5d2ce07: **Perf:** add blocking for concurrent requests with same cache key.
|
|
157
|
+
- Updated dependencies [0c7db81]
|
|
158
|
+
- keq@5.0.0-alpha.27
|
|
159
|
+
|
|
160
|
+
## 5.0.0-alpha.26
|
|
161
|
+
|
|
162
|
+
### Patch Changes
|
|
163
|
+
|
|
164
|
+
- Updated dependencies [22ce01a]
|
|
165
|
+
- Updated dependencies [63161c4]
|
|
166
|
+
- keq@5.0.0-alpha.26
|
|
167
|
+
|
|
168
|
+
## 5.0.0-alpha.25
|
|
169
|
+
|
|
170
|
+
### Minor Changes
|
|
171
|
+
|
|
172
|
+
- d1090d3: **Feat:** add debug logs and Server-Timing header.
|
|
173
|
+
|
|
174
|
+
### Patch Changes
|
|
175
|
+
|
|
176
|
+
- Updated dependencies [214ae66]
|
|
177
|
+
- Updated dependencies [9290139]
|
|
178
|
+
- keq@5.0.0-alpha.25
|
|
179
|
+
|
|
180
|
+
## 5.0.0-alpha.24
|
|
181
|
+
|
|
182
|
+
### Patch Changes
|
|
183
|
+
|
|
184
|
+
- Updated dependencies [0a2eb2f]
|
|
185
|
+
- keq@5.0.0-alpha.24
|
|
186
|
+
|
|
187
|
+
## 5.0.0-alpha.23
|
|
188
|
+
|
|
189
|
+
### Major Changes
|
|
190
|
+
|
|
191
|
+
- 5f5bdd9: **BREAKING CHANGE:** Simplified KeqCacheStrategy interface.
|
|
192
|
+
|
|
193
|
+
### Minor Changes
|
|
194
|
+
|
|
195
|
+
- 9ab2c64: Convert non-essential cli tasks into plugins.
|
|
196
|
+
|
|
197
|
+
### Patch Changes
|
|
198
|
+
|
|
199
|
+
- b8d68c7: **Fix:** IndexedDBStorage cannot evict ttl cache
|
|
200
|
+
- 20c7067: **Fix:** Failed to automatically clean up expired cache data when get immediately after initialization.
|
|
201
|
+
- 9a9caa4: Cannot call CacheEntry.response.json multiple times.
|
|
202
|
+
- Updated dependencies [842e555]
|
|
203
|
+
- Updated dependencies [7873a0a]
|
|
204
|
+
- keq@5.0.0-alpha.23
|
|
205
|
+
|
|
206
|
+
## 5.0.0-alpha.22
|
|
207
|
+
|
|
208
|
+
### Patch Changes
|
|
209
|
+
|
|
210
|
+
- Updated dependencies [df114d1]
|
|
211
|
+
- keq@5.0.0-alpha.22
|
|
212
|
+
|
|
213
|
+
## 5.0.0-alpha.21
|
|
214
|
+
|
|
215
|
+
### Minor Changes
|
|
216
|
+
|
|
217
|
+
- 25414cb: add print method to display MemoryStorage entries
|
|
218
|
+
|
|
219
|
+
### Patch Changes
|
|
220
|
+
|
|
221
|
+
- Updated dependencies [90311b3]
|
|
222
|
+
- keq@5.0.0-alpha.21
|
|
223
|
+
|
|
224
|
+
## 5.0.0-alpha.20
|
|
225
|
+
|
|
226
|
+
### Patch Changes
|
|
227
|
+
|
|
228
|
+
- Updated dependencies [1f367c0]
|
|
229
|
+
- keq@5.0.0-alpha.20
|
|
230
|
+
|
|
231
|
+
## 5.0.0-alpha.19
|
|
232
|
+
|
|
233
|
+
### Patch Changes
|
|
234
|
+
|
|
235
|
+
- keq@5.0.0-alpha.19
|
|
236
|
+
|
|
237
|
+
## 5.0.0-alpha.18
|
|
238
|
+
|
|
239
|
+
### Patch Changes
|
|
240
|
+
|
|
241
|
+
- Updated dependencies [cbc5d17]
|
|
242
|
+
- keq@5.0.0-alpha.18
|
|
243
|
+
|
|
244
|
+
## 5.0.0-alpha.17
|
|
245
|
+
|
|
246
|
+
### Patch Changes
|
|
247
|
+
|
|
248
|
+
- Updated dependencies [d472648]
|
|
249
|
+
- Updated dependencies [eed26f9]
|
|
250
|
+
- keq@5.0.0-alpha.17
|
|
251
|
+
|
|
252
|
+
## 5.0.0-alpha.16
|
|
253
|
+
|
|
254
|
+
### Patch Changes
|
|
255
|
+
|
|
256
|
+
- Updated dependencies [ca6c879]
|
|
257
|
+
- keq@5.0.0-alpha.16
|
|
258
|
+
|
|
259
|
+
## 5.0.0-alpha.15
|
|
260
|
+
|
|
261
|
+
### Patch Changes
|
|
262
|
+
|
|
263
|
+
- keq@5.0.0-alpha.15
|
|
264
|
+
|
|
265
|
+
## 5.0.0-alpha.14
|
|
266
|
+
|
|
267
|
+
### Patch Changes
|
|
268
|
+
|
|
269
|
+
- keq@5.0.0-alpha.14
|
|
270
|
+
|
|
271
|
+
## 5.0.0-alpha.13
|
|
272
|
+
|
|
273
|
+
### Patch Changes
|
|
274
|
+
|
|
275
|
+
- keq@5.0.0-alpha.13
|
|
276
|
+
|
|
277
|
+
## 5.0.0-alpha.12
|
|
278
|
+
|
|
279
|
+
### Patch Changes
|
|
280
|
+
|
|
281
|
+
- 581815a: ensure compatibility
|
|
282
|
+
- Updated dependencies [581815a]
|
|
283
|
+
- keq@5.0.0-alpha.12
|
|
284
|
+
|
|
285
|
+
## 5.0.0-alpha.11
|
|
286
|
+
|
|
287
|
+
### Minor Changes
|
|
288
|
+
|
|
289
|
+
- 54520a9: **Feat:** using `.option('cache', false)` can disable caching for request that are cached by default
|
|
290
|
+
- 89274bd: **Feat:** add a Size enum make it easier to set the size
|
|
291
|
+
|
|
292
|
+
### Patch Changes
|
|
293
|
+
|
|
294
|
+
- Updated dependencies [c7ffd1f]
|
|
295
|
+
- keq@5.0.0-alpha.11
|
|
296
|
+
|
|
297
|
+
## 5.0.0-alpha.10
|
|
298
|
+
|
|
299
|
+
### Patch Changes
|
|
300
|
+
|
|
301
|
+
- e7eb9dc: Don't publish .turbo and jest.config.cts to npm
|
|
302
|
+
- 7343445: Incorrect build before release
|
|
303
|
+
- Updated dependencies [e7eb9dc]
|
|
304
|
+
- Updated dependencies [7343445]
|
|
305
|
+
- keq@5.0.0-alpha.10
|
|
306
|
+
|
|
307
|
+
## 5.0.0-alpha.9
|
|
308
|
+
|
|
309
|
+
### Patch Changes
|
|
310
|
+
|
|
311
|
+
- 2686b8d: build with burbo
|
|
312
|
+
- 2686b8d: remove private dependencies
|
|
313
|
+
- Updated dependencies [2686b8d]
|
|
314
|
+
- Updated dependencies [2686b8d]
|
|
315
|
+
- keq@5.0.0-alpha.9
|
|
316
|
+
|
|
317
|
+
## 5.0.0-alpha.8
|
|
318
|
+
|
|
319
|
+
### Patch Changes
|
|
320
|
+
|
|
321
|
+
- 0873c7e: Incorrect build before release.
|
|
322
|
+
- Updated dependencies [0873c7e]
|
|
323
|
+
- keq@5.0.0-alpha.8
|
|
324
|
+
|
|
3
325
|
## 5.0.0-alpha.7
|
|
4
326
|
|
|
5
327
|
### Major Changes
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { queueAsPromised } from "fastq";
|
|
2
|
+
import { Keq, KeqContext, KeqExecutionContext, KeqMiddleware, KeqNext } from "keq";
|
|
3
|
+
import { Promisable } from "type-fest";
|
|
4
|
+
|
|
5
|
+
//#region src/cache-entry/types/cache-entry-options.d.ts
|
|
6
|
+
interface CacheEntryOptions {
|
|
7
|
+
key: string;
|
|
8
|
+
response: Response;
|
|
9
|
+
size: number;
|
|
10
|
+
expiredAt?: Date;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/cache-entry/types/cache-entry-build-options.d.ts
|
|
14
|
+
interface CacheEntryBuildOptions {
|
|
15
|
+
key: string;
|
|
16
|
+
response: Response;
|
|
17
|
+
size?: number;
|
|
18
|
+
ttl?: number;
|
|
19
|
+
expiredAt?: Date;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/cache-entry/cache-entry.d.ts
|
|
23
|
+
declare class CacheEntry {
|
|
24
|
+
key: string;
|
|
25
|
+
response: Response;
|
|
26
|
+
/**
|
|
27
|
+
* @en bytes
|
|
28
|
+
* @zh 字节数
|
|
29
|
+
*/
|
|
30
|
+
size: number;
|
|
31
|
+
expiredAt: Date;
|
|
32
|
+
constructor(options: CacheEntryOptions);
|
|
33
|
+
static build(options: CacheEntryBuildOptions): Promise<CacheEntry>;
|
|
34
|
+
clone(): CacheEntry;
|
|
35
|
+
assignResponseHeaders(headers: Headers): void;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/storage/keq-cache-storage.d.ts
|
|
39
|
+
declare abstract class KeqCacheStorage {
|
|
40
|
+
/**
|
|
41
|
+
* @en Get the length of the storage
|
|
42
|
+
* @zh 获取 Storage 缓存的条目数量
|
|
43
|
+
*/
|
|
44
|
+
abstract get(key: string): Promisable<CacheEntry | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* @en Set a new entry to the storage
|
|
47
|
+
* @zh 将被缓存的数据添加到Storage中
|
|
48
|
+
*/
|
|
49
|
+
abstract set(entry: CacheEntry): Promisable<void>;
|
|
50
|
+
/**
|
|
51
|
+
* @en Remove an entry by key
|
|
52
|
+
* @zh 根据key删除Storage中的数据
|
|
53
|
+
*/
|
|
54
|
+
abstract remove(key: string): Promisable<void>;
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/types/keq-cache-key.d.ts
|
|
58
|
+
type KeqCacheKeyFactory = ((context: KeqContext) => string);
|
|
59
|
+
type KeqCacheKey = string | KeqCacheKeyFactory;
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/constants/eviction.enum.d.ts
|
|
62
|
+
declare enum Eviction {
|
|
63
|
+
LRU = "lru",
|
|
64
|
+
LFU = "lfu",
|
|
65
|
+
RANDOM = "random",
|
|
66
|
+
TTL = "ttl"
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/constants/size.enum.d.ts
|
|
70
|
+
declare enum Size {
|
|
71
|
+
B = 1,
|
|
72
|
+
KB = 1024,
|
|
73
|
+
MB = 1048576,
|
|
74
|
+
GB = 1073741824
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/constants/strategy.enum.d.ts
|
|
78
|
+
declare const Strategy: {
|
|
79
|
+
STALE_WHILE_REVALIDATE: KeqCacheStrategy;
|
|
80
|
+
NETWORK_FIRST: KeqCacheStrategy;
|
|
81
|
+
NETWORK_ONLY: KeqCacheStrategy;
|
|
82
|
+
CACHE_FIRST: KeqCacheStrategy;
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/storage/internal-storage/types/events.d.ts
|
|
86
|
+
interface OnCacheGetEvent {
|
|
87
|
+
readonly key: string;
|
|
88
|
+
}
|
|
89
|
+
interface OnCacheSetEvent {
|
|
90
|
+
readonly key: string;
|
|
91
|
+
}
|
|
92
|
+
interface OnCacheRemoveEvent {
|
|
93
|
+
readonly key: string;
|
|
94
|
+
}
|
|
95
|
+
interface OnCacheEvictEvent {
|
|
96
|
+
readonly keys: string[];
|
|
97
|
+
}
|
|
98
|
+
interface OnCacheExpiredEvent {
|
|
99
|
+
readonly keys: string[];
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/storage/internal-storage/types/storage-options.d.ts
|
|
103
|
+
interface InternalStorageOptions {
|
|
104
|
+
/**
|
|
105
|
+
* @default false
|
|
106
|
+
*/
|
|
107
|
+
debug?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* @en bytes
|
|
110
|
+
* @zh 字节数
|
|
111
|
+
*
|
|
112
|
+
* @default Infinity
|
|
113
|
+
*/
|
|
114
|
+
size?: number;
|
|
115
|
+
onCacheGet?: (event: OnCacheGetEvent) => void;
|
|
116
|
+
onCacheSet?: (event: OnCacheSetEvent) => void;
|
|
117
|
+
onCacheRemove?: (event: OnCacheRemoveEvent) => void;
|
|
118
|
+
onCacheEvict?: (event: OnCacheEvictEvent) => void;
|
|
119
|
+
onCacheExpired?: (event: OnCacheExpiredEvent) => void;
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/storage/memory-storage/types/memory-storage-options.d.ts
|
|
123
|
+
interface MemoryStorageOptions extends InternalStorageOptions {
|
|
124
|
+
/**
|
|
125
|
+
* @default Eviction.LRU
|
|
126
|
+
*/
|
|
127
|
+
eviction?: Eviction;
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/storage/memory-storage/memory-storage.d.ts
|
|
131
|
+
declare class MemoryStorage extends KeqCacheStorage {
|
|
132
|
+
private storage;
|
|
133
|
+
constructor(options?: MemoryStorageOptions);
|
|
134
|
+
set(entry: CacheEntry): Promisable<void>;
|
|
135
|
+
get(key: string): Promisable<CacheEntry | undefined>;
|
|
136
|
+
remove(key: string): Promisable<void>;
|
|
137
|
+
print(): Promise<void>;
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/storage/indexed-db-storage/types/indexed-db-storage-options.d.ts
|
|
141
|
+
interface IndexedDbStorageOptions extends InternalStorageOptions {
|
|
142
|
+
/**
|
|
143
|
+
* @en The table name for the IndexedDB storage, multiple instances using the same table name will share the cached data.
|
|
144
|
+
* @zh IndexedDB 存储的表名, 多个实例使用同一个表名会共享缓存数据。
|
|
145
|
+
*/
|
|
146
|
+
tableName?: string;
|
|
147
|
+
/**
|
|
148
|
+
* @default Eviction.LRU
|
|
149
|
+
*/
|
|
150
|
+
eviction?: Eviction;
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/storage/indexed-db-storage/indexed-db-storage.d.ts
|
|
154
|
+
declare class IndexedDBStorage extends KeqCacheStorage {
|
|
155
|
+
private storage;
|
|
156
|
+
constructor(options?: IndexedDbStorageOptions);
|
|
157
|
+
set(entry: CacheEntry): Promisable<void>;
|
|
158
|
+
get(key: string): Promisable<CacheEntry | undefined>;
|
|
159
|
+
remove(key: string): Promisable<void>;
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/storage/multi-tier-storage/types/multi-tier-storage-options.d.ts
|
|
163
|
+
interface MultiTierStorageOptions {
|
|
164
|
+
tiers: KeqCacheStorage[];
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/storage/multi-tier-storage/multi-tier-storage.d.ts
|
|
168
|
+
/**
|
|
169
|
+
* @en Multi-tier cache storage that manages multiple KeqCacheStorage instances in tiers
|
|
170
|
+
* @zh 多层缓存存储,管理多个分层的 KeqCacheStorage 实例
|
|
171
|
+
*/
|
|
172
|
+
declare class MultiTierStorage extends KeqCacheStorage {
|
|
173
|
+
private readonly storages;
|
|
174
|
+
/**
|
|
175
|
+
* @param storages Array of storage instances ordered by performance (fastest first)
|
|
176
|
+
* @zh 按性价比排序的存储实例数组,排在前面的成本低,排在后面的成本高
|
|
177
|
+
*/
|
|
178
|
+
constructor(options: MultiTierStorageOptions);
|
|
179
|
+
/**
|
|
180
|
+
* @en Get cache entry, searching from lowest to highest tier
|
|
181
|
+
* @zh 获取缓存条目,从最底层到高层依次搜索
|
|
182
|
+
*/
|
|
183
|
+
get(key: string): Promise<CacheEntry | undefined>;
|
|
184
|
+
/**
|
|
185
|
+
* @en Set cache entry to all tiers concurrently
|
|
186
|
+
* @zh 并发写入所有层的缓存
|
|
187
|
+
*/
|
|
188
|
+
set(entry: CacheEntry): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* @en Remove cache entry from all tiers
|
|
191
|
+
* @zh 从所有层删除缓存条目
|
|
192
|
+
*/
|
|
193
|
+
remove(key: string): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* @en Sync cache entry to all lower tiers (tiers with index < currentTierIndex)
|
|
196
|
+
* @zh 将缓存条目同步到所有低层存储(索引小于当前层的存储)
|
|
197
|
+
*/
|
|
198
|
+
private syncToLowerTiers;
|
|
199
|
+
}
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/storage/tier-storage/types/tier-storage-options.d.ts
|
|
202
|
+
/**
|
|
203
|
+
* @en Configuration options for TierStorage
|
|
204
|
+
* @zh TierStorage 的配置选项
|
|
205
|
+
*/
|
|
206
|
+
interface TierStorageOptions {
|
|
207
|
+
/**
|
|
208
|
+
* @en Memory storage instance or options for the memory storage (L1 cache)
|
|
209
|
+
* @zh 内存存储实例或配置选项(一级缓存)
|
|
210
|
+
*/
|
|
211
|
+
memory?: MemoryStorage | MemoryStorageOptions;
|
|
212
|
+
/**
|
|
213
|
+
* @en IndexedDB storage instance or options for the IndexedDB storage (L2 cache)
|
|
214
|
+
* @zh IndexedDB 存储实例或配置选项(二级缓存)
|
|
215
|
+
*/
|
|
216
|
+
indexedDB?: IndexedDBStorage | IndexedDbStorageOptions;
|
|
217
|
+
}
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/storage/tier-storage/tier-storage.d.ts
|
|
220
|
+
/**
|
|
221
|
+
* @en Two-tier cache storage that combines MemoryStorage (L1) and IndexedDBStorage (L2)
|
|
222
|
+
* @zh 二级缓存存储,结合了MemoryStorage(一级)和IndexedDBStorage(二级)
|
|
223
|
+
*
|
|
224
|
+
* This is a convenience wrapper around MultiTierStorage that provides:
|
|
225
|
+
* - Fast in-memory cache (L1)
|
|
226
|
+
* - Persistent IndexedDB cache (L2)
|
|
227
|
+
* - Simplified configuration options
|
|
228
|
+
*/
|
|
229
|
+
declare class TierStorage extends MultiTierStorage {
|
|
230
|
+
constructor(options?: TierStorageOptions);
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/request-cache-handler/request-cache-handler.d.ts
|
|
234
|
+
type RequestCacheHandlerOptions = Omit<RequestCacheOptions, 'strategy'>;
|
|
235
|
+
declare class RequestCacheHandler {
|
|
236
|
+
readonly cacheKey: string;
|
|
237
|
+
readonly storage: KeqCacheStorage;
|
|
238
|
+
readonly options: Readonly<RequestCacheHandlerOptions>;
|
|
239
|
+
constructor(cacheKey: string, storage: KeqCacheStorage, options: Readonly<RequestCacheHandlerOptions>);
|
|
240
|
+
/**
|
|
241
|
+
* Resolve cache key for request context
|
|
242
|
+
*/
|
|
243
|
+
static resolveRequestCacheKey(context: KeqContext, options: RequestCacheHandlerOptions): string;
|
|
244
|
+
/**
|
|
245
|
+
* Get cache from storage
|
|
246
|
+
*/
|
|
247
|
+
getCache(): Promise<[string, CacheEntry | undefined]>;
|
|
248
|
+
/**
|
|
249
|
+
* Store response that in context to storage
|
|
250
|
+
*/
|
|
251
|
+
setCache(context: KeqContext): Promise<[string, CacheEntry | undefined]>;
|
|
252
|
+
}
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/types/keq-cache-strategy.d.ts
|
|
255
|
+
interface KeqCacheStrategy {
|
|
256
|
+
(handler: RequestCacheHandler, context: KeqExecutionContext, next: KeqNext): Promise<void>;
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/types/request-cache-options.d.ts
|
|
260
|
+
/**
|
|
261
|
+
* The options for a cacheable request.
|
|
262
|
+
*/
|
|
263
|
+
interface RequestCacheOptions {
|
|
264
|
+
/**
|
|
265
|
+
* Enable debug logs
|
|
266
|
+
*/
|
|
267
|
+
debug?: boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Enable Server-Timing header
|
|
270
|
+
*/
|
|
271
|
+
serverTiming?: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* This configuration item controls whether requests are allowed to be concurrent.
|
|
274
|
+
* By default, concurrency is disabled
|
|
275
|
+
*
|
|
276
|
+
* When multiple requests with the same key occur,
|
|
277
|
+
* the subsequent ones are blocked until the previous request completes.
|
|
278
|
+
* This ensures that the cache is utilized effectively and prevents redundant processing for identical keys
|
|
279
|
+
*
|
|
280
|
+
* @default false
|
|
281
|
+
*/
|
|
282
|
+
concurrent?: boolean;
|
|
283
|
+
/**
|
|
284
|
+
* Cache Key
|
|
285
|
+
*/
|
|
286
|
+
key?: KeqCacheKey;
|
|
287
|
+
/**
|
|
288
|
+
* @default Strategy.NETWORK_FIRST
|
|
289
|
+
*/
|
|
290
|
+
strategy: KeqCacheStrategy;
|
|
291
|
+
/**
|
|
292
|
+
* @en seconds
|
|
293
|
+
* @zh 秒
|
|
294
|
+
*
|
|
295
|
+
* @default Infinity
|
|
296
|
+
*/
|
|
297
|
+
ttl?: number;
|
|
298
|
+
/**
|
|
299
|
+
* If exclude is true, the request will not be cached.
|
|
300
|
+
*/
|
|
301
|
+
exclude?: (res: Response) => (Promise<boolean> | boolean);
|
|
302
|
+
}
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region src/types/keq-cache-pattern.d.ts
|
|
305
|
+
type KeqCachePattern = RegExp | ((ctx: KeqContext) => boolean) | true;
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/types/keq-cache-rule.d.ts
|
|
308
|
+
interface KeqCacheRule extends RequestCacheOptions {
|
|
309
|
+
pattern?: KeqCachePattern;
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/cache.d.ts
|
|
313
|
+
interface KeqCacheOptions extends Pick<RequestCacheOptions, 'serverTiming'> {
|
|
314
|
+
storage: KeqCacheStorage;
|
|
315
|
+
/**
|
|
316
|
+
* Cache Key Factory
|
|
317
|
+
*/
|
|
318
|
+
keyFactory?: KeqCacheKeyFactory;
|
|
319
|
+
rules?: KeqCacheRule[];
|
|
320
|
+
}
|
|
321
|
+
declare module 'keq' {
|
|
322
|
+
interface KeqMiddlewareOptions<OP> {
|
|
323
|
+
/**
|
|
324
|
+
* [keq-cache](https://github.com/keq-request/keq-cache)
|
|
325
|
+
*/
|
|
326
|
+
cache(option: RequestCacheOptions | false): Keq<OP>;
|
|
327
|
+
}
|
|
328
|
+
interface KeqEvents {
|
|
329
|
+
'cache:hit': {
|
|
330
|
+
key: string;
|
|
331
|
+
response: Response;
|
|
332
|
+
context: KeqContext;
|
|
333
|
+
};
|
|
334
|
+
'cache:miss': {
|
|
335
|
+
key: string;
|
|
336
|
+
context: KeqContext;
|
|
337
|
+
};
|
|
338
|
+
'cache:update': {
|
|
339
|
+
key: string;
|
|
340
|
+
oldResponse?: Response;
|
|
341
|
+
newResponse: Response;
|
|
342
|
+
context: KeqContext;
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
interface KeqGlobalCore {
|
|
346
|
+
cache?: Record<string, queueAsPromised<{
|
|
347
|
+
next: KeqNext;
|
|
348
|
+
}, void>>;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
declare function cache(options: KeqCacheOptions): KeqMiddleware;
|
|
352
|
+
//#endregion
|
|
353
|
+
export { Eviction, IndexedDBStorage, type IndexedDbStorageOptions, type KeqCacheKey, type KeqCacheKeyFactory, KeqCacheOptions, type KeqCachePattern, type KeqCacheRule, KeqCacheStorage, type KeqCacheStrategy, MemoryStorage, type MemoryStorageOptions, MultiTierStorage, type MultiTierStorageOptions, Size, Strategy, TierStorage, type TierStorageOptions, cache };
|
|
354
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/cache-entry/types/cache-entry-options.ts","../src/cache-entry/types/cache-entry-build-options.ts","../src/cache-entry/cache-entry.ts","../src/storage/keq-cache-storage.ts","../src/types/keq-cache-key.ts","../src/constants/eviction.enum.ts","../src/constants/size.enum.ts","../src/constants/strategy.enum.ts","../src/storage/internal-storage/types/events.ts","../src/storage/internal-storage/types/storage-options.ts","../src/storage/memory-storage/types/memory-storage-options.ts","../src/storage/memory-storage/memory-storage.ts","../src/storage/indexed-db-storage/types/indexed-db-storage-options.ts","../src/storage/indexed-db-storage/indexed-db-storage.ts","../src/storage/multi-tier-storage/types/multi-tier-storage-options.ts","../src/storage/multi-tier-storage/multi-tier-storage.ts","../src/storage/tier-storage/types/tier-storage-options.ts","../src/storage/tier-storage/tier-storage.ts","../src/request-cache-handler/request-cache-handler.ts","../src/types/keq-cache-strategy.ts","../src/types/request-cache-options.ts","../src/types/keq-cache-pattern.ts","../src/types/keq-cache-rule.ts","../src/cache.ts"],"mappings":";;;;;UAAiB,iBAAA;EACf,GAAA;EACA,QAAA,EAAU,QAAA;EACV,IAAA;EACA,SAAA,GAAY,IAAA;AAAA;;;UCJG,sBAAA;EACf,GAAA;EACA,QAAA,EAAU,QAAA;EACV,IAAA;EACA,GAAA;EACA,SAAA,GAAY,IAAA;AAAA;;;cCED,UAAA;EACX,GAAA;EACA,QAAA,EAAU,QAAA;;AFTZ;;;EEeE,IAAA;EAEA,SAAA,EAAW,IAAA;cAEC,OAAA,EAAS,iBAAA;EAAA,OAOR,KAAA,CAAM,OAAA,EAAS,sBAAA,GAAyB,OAAA,CAAQ,UAA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