cacheable 1.8.0 → 1.8.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.md +48 -23
- package/dist/index.cjs +380 -0
- package/dist/index.d.cts +393 -2
- package/dist/index.d.ts +393 -2
- package/dist/index.js +380 -0
- package/package.json +6 -3
package/dist/index.d.ts
CHANGED
|
@@ -17,16 +17,58 @@ declare class CacheableStats {
|
|
|
17
17
|
private _count;
|
|
18
18
|
private _enabled;
|
|
19
19
|
constructor(options?: CacheableOptions$1);
|
|
20
|
+
/**
|
|
21
|
+
* @returns {boolean} - Whether the stats are enabled
|
|
22
|
+
*/
|
|
20
23
|
get enabled(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* @param {boolean} enabled - Whether to enable the stats
|
|
26
|
+
*/
|
|
21
27
|
set enabled(enabled: boolean);
|
|
28
|
+
/**
|
|
29
|
+
* @returns {number} - The number of hits
|
|
30
|
+
* @readonly
|
|
31
|
+
*/
|
|
22
32
|
get hits(): number;
|
|
33
|
+
/**
|
|
34
|
+
* @returns {number} - The number of misses
|
|
35
|
+
* @readonly
|
|
36
|
+
*/
|
|
23
37
|
get misses(): number;
|
|
38
|
+
/**
|
|
39
|
+
* @returns {number} - The number of gets
|
|
40
|
+
* @readonly
|
|
41
|
+
*/
|
|
24
42
|
get gets(): number;
|
|
43
|
+
/**
|
|
44
|
+
* @returns {number} - The number of sets
|
|
45
|
+
* @readonly
|
|
46
|
+
*/
|
|
25
47
|
get sets(): number;
|
|
48
|
+
/**
|
|
49
|
+
* @returns {number} - The number of deletes
|
|
50
|
+
* @readonly
|
|
51
|
+
*/
|
|
26
52
|
get deletes(): number;
|
|
53
|
+
/**
|
|
54
|
+
* @returns {number} - The number of clears
|
|
55
|
+
* @readonly
|
|
56
|
+
*/
|
|
27
57
|
get clears(): number;
|
|
58
|
+
/**
|
|
59
|
+
* @returns {number} - The vsize (value size) of the cache instance
|
|
60
|
+
* @readonly
|
|
61
|
+
*/
|
|
28
62
|
get vsize(): number;
|
|
63
|
+
/**
|
|
64
|
+
* @returns {number} - The ksize (key size) of the cache instance
|
|
65
|
+
* @readonly
|
|
66
|
+
*/
|
|
29
67
|
get ksize(): number;
|
|
68
|
+
/**
|
|
69
|
+
* @returns {number} - The count of the cache instance
|
|
70
|
+
* @readonly
|
|
71
|
+
*/
|
|
30
72
|
get count(): number;
|
|
31
73
|
incrementHits(): void;
|
|
32
74
|
incrementMisses(): void;
|
|
@@ -47,6 +89,15 @@ declare class CacheableStats {
|
|
|
47
89
|
resetStoreValues(): void;
|
|
48
90
|
}
|
|
49
91
|
|
|
92
|
+
/**
|
|
93
|
+
* CacheableItem
|
|
94
|
+
* @typedef {Object} CacheableItem
|
|
95
|
+
* @property {string} key - The key of the cacheable item
|
|
96
|
+
* @property {any} value - The value of the cacheable item
|
|
97
|
+
* @property {number|string} [ttl] - Time to Live - If you set a number it is miliseconds, if you set a string it is a human-readable
|
|
98
|
+
* format such as `1s` for 1 second or `1h` for 1 hour. Setting undefined means that it will use the default time-to-live. If both are
|
|
99
|
+
* undefined then it will not have a time-to-live.
|
|
100
|
+
*/
|
|
50
101
|
type CacheableItem = {
|
|
51
102
|
key: string;
|
|
52
103
|
value: any;
|
|
@@ -58,6 +109,15 @@ type CacheableStoreItem = {
|
|
|
58
109
|
expires?: number;
|
|
59
110
|
};
|
|
60
111
|
|
|
112
|
+
/**
|
|
113
|
+
* @typedef {Object} CacheableMemoryOptions
|
|
114
|
+
* @property {number|string} [ttl] - Time to Live - If you set a number it is miliseconds, if you set a string it is a human-readable
|
|
115
|
+
* format such as `1s` for 1 second or `1h` for 1 hour. Setting undefined means that it will use the default time-to-live. If both are
|
|
116
|
+
* undefined then it will not have a time-to-live.
|
|
117
|
+
* @property {boolean} [useClone] - If true, it will clone the value before returning it. If false, it will return the value directly. Default is true.
|
|
118
|
+
* @property {number} [lruSize] - The size of the LRU cache. If set to 0, it will not use LRU cache. Default is 0.
|
|
119
|
+
* @property {number} [checkInterval] - The interval to check for expired items. If set to 0, it will not check for expired items. Default is 0.
|
|
120
|
+
*/
|
|
61
121
|
type CacheableMemoryOptions = {
|
|
62
122
|
ttl?: number | string;
|
|
63
123
|
useClone?: boolean;
|
|
@@ -82,40 +142,209 @@ declare class CacheableMemory {
|
|
|
82
142
|
private _lruSize;
|
|
83
143
|
private _checkInterval;
|
|
84
144
|
private _interval;
|
|
145
|
+
/**
|
|
146
|
+
* @constructor
|
|
147
|
+
* @param {CacheableMemoryOptions} [options] - The options for the CacheableMemory
|
|
148
|
+
*/
|
|
85
149
|
constructor(options?: CacheableMemoryOptions);
|
|
150
|
+
/**
|
|
151
|
+
* Gets the time-to-live
|
|
152
|
+
* @returns {number|string|undefined} - The time-to-live in miliseconds or a human-readable format. If undefined, it will not have a time-to-live.
|
|
153
|
+
*/
|
|
86
154
|
get ttl(): number | string | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Sets the time-to-live
|
|
157
|
+
* @param {number|string|undefined} value - The time-to-live in miliseconds or a human-readable format (example '1s' = 1 second, '1h' = 1 hour). If undefined, it will not have a time-to-live.
|
|
158
|
+
*/
|
|
87
159
|
set ttl(value: number | string | undefined);
|
|
160
|
+
/**
|
|
161
|
+
* Gets whether to use clone
|
|
162
|
+
* @returns {boolean} - If true, it will clone the value before returning it. If false, it will return the value directly. Default is true.
|
|
163
|
+
*/
|
|
88
164
|
get useClone(): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Sets whether to use clone
|
|
167
|
+
* @param {boolean} value - If true, it will clone the value before returning it. If false, it will return the value directly. Default is true.
|
|
168
|
+
*/
|
|
89
169
|
set useClone(value: boolean);
|
|
170
|
+
/**
|
|
171
|
+
* Gets the size of the LRU cache
|
|
172
|
+
* @returns {number} - The size of the LRU cache. If set to 0, it will not use LRU cache. Default is 0.
|
|
173
|
+
*/
|
|
90
174
|
get lruSize(): number;
|
|
175
|
+
/**
|
|
176
|
+
* Sets the size of the LRU cache
|
|
177
|
+
* @param {number} value - The size of the LRU cache. If set to 0, it will not use LRU cache. Default is 0.
|
|
178
|
+
*/
|
|
91
179
|
set lruSize(value: number);
|
|
180
|
+
/**
|
|
181
|
+
* Gets the check interval
|
|
182
|
+
* @returns {number} - The interval to check for expired items. If set to 0, it will not check for expired items. Default is 0.
|
|
183
|
+
*/
|
|
92
184
|
get checkInterval(): number;
|
|
185
|
+
/**
|
|
186
|
+
* Sets the check interval
|
|
187
|
+
* @param {number} value - The interval to check for expired items. If set to 0, it will not check for expired items. Default is 0.
|
|
188
|
+
*/
|
|
93
189
|
set checkInterval(value: number);
|
|
190
|
+
/**
|
|
191
|
+
* Gets the size of the cache
|
|
192
|
+
* @returns {number} - The size of the cache
|
|
193
|
+
*/
|
|
94
194
|
get size(): number;
|
|
195
|
+
/**
|
|
196
|
+
* Gets the keys
|
|
197
|
+
* @returns {IterableIterator<string>} - The keys
|
|
198
|
+
*/
|
|
95
199
|
get keys(): IterableIterator<string>;
|
|
200
|
+
/**
|
|
201
|
+
* Gets the items
|
|
202
|
+
* @returns {IterableIterator<CacheableStoreItem>} - The items
|
|
203
|
+
*/
|
|
96
204
|
get items(): IterableIterator<CacheableStoreItem>;
|
|
205
|
+
/**
|
|
206
|
+
* Gets the value of the key
|
|
207
|
+
* @param {string} key - The key to get the value
|
|
208
|
+
* @returns {T | undefined} - The value of the key
|
|
209
|
+
*/
|
|
97
210
|
get<T>(key: string): T | undefined;
|
|
211
|
+
/**
|
|
212
|
+
* Gets the values of the keys
|
|
213
|
+
* @param {string[]} keys - The keys to get the values
|
|
214
|
+
* @returns {T[]} - The values of the keys
|
|
215
|
+
*/
|
|
98
216
|
getMany<T>(keys: string[]): T[];
|
|
217
|
+
/**
|
|
218
|
+
* Gets the raw value of the key
|
|
219
|
+
* @param {string} key - The key to get the value
|
|
220
|
+
* @returns {CacheableStoreItem | undefined} - The raw value of the key
|
|
221
|
+
*/
|
|
99
222
|
getRaw(key: string): CacheableStoreItem | undefined;
|
|
223
|
+
/**
|
|
224
|
+
* Gets the raw values of the keys
|
|
225
|
+
* @param {string[]} keys - The keys to get the values
|
|
226
|
+
* @returns {CacheableStoreItem[]} - The raw values of the keys
|
|
227
|
+
*/
|
|
100
228
|
getManyRaw(keys: string[]): Array<CacheableStoreItem | undefined>;
|
|
229
|
+
/**
|
|
230
|
+
* Sets the value of the key
|
|
231
|
+
* @param {string} key - The key to set the value
|
|
232
|
+
* @param {any} value - The value to set
|
|
233
|
+
* @param {number|string} [ttl] - Time to Live - If you set a number it is miliseconds, if you set a string it is a human-readable.
|
|
234
|
+
* If you set undefined, it will use the default time-to-live. If both are undefined then it will not have a time-to-live.
|
|
235
|
+
* @returns {void}
|
|
236
|
+
*/
|
|
101
237
|
set(key: string, value: any, ttl?: number | string): void;
|
|
238
|
+
/**
|
|
239
|
+
* Sets the values of the keys
|
|
240
|
+
* @param {CacheableItem[]} items - The items to set
|
|
241
|
+
* @returns {void}
|
|
242
|
+
*/
|
|
102
243
|
setMany(items: CacheableItem[]): void;
|
|
244
|
+
/**
|
|
245
|
+
* Checks if the key exists
|
|
246
|
+
* @param {string} key - The key to check
|
|
247
|
+
* @returns {boolean} - If true, the key exists. If false, the key does not exist.
|
|
248
|
+
*/
|
|
103
249
|
has(key: string): boolean;
|
|
104
|
-
|
|
105
|
-
|
|
250
|
+
/**
|
|
251
|
+
* @function hasMany
|
|
252
|
+
* @param {string[]} keys - The keys to check
|
|
253
|
+
* @returns {boolean[]} - If true, the key exists. If false, the key does not exist.
|
|
254
|
+
*/
|
|
255
|
+
hasMany(keys: string[]): boolean[];
|
|
256
|
+
/**
|
|
257
|
+
* Take will get the key and delete the entry from cache
|
|
258
|
+
* @param {string} key - The key to take
|
|
259
|
+
* @returns {T | undefined} - The value of the key
|
|
260
|
+
*/
|
|
261
|
+
take<T>(key: string): T | undefined;
|
|
262
|
+
/**
|
|
263
|
+
* TakeMany will get the keys and delete the entries from cache
|
|
264
|
+
* @param {string[]} keys - The keys to take
|
|
265
|
+
* @returns {T[]} - The values of the keys
|
|
266
|
+
*/
|
|
267
|
+
takeMany<T>(keys: string[]): T[];
|
|
268
|
+
/**
|
|
269
|
+
* Delete the key
|
|
270
|
+
* @param {string} key - The key to delete
|
|
271
|
+
* @returns {void}
|
|
272
|
+
*/
|
|
106
273
|
delete(key: string): void;
|
|
274
|
+
/**
|
|
275
|
+
* Delete the keys
|
|
276
|
+
* @param {string[]} keys - The keys to delete
|
|
277
|
+
* @returns {void}
|
|
278
|
+
*/
|
|
107
279
|
deleteMany(keys: string[]): void;
|
|
280
|
+
/**
|
|
281
|
+
* Clear the cache
|
|
282
|
+
* @returns {void}
|
|
283
|
+
*/
|
|
108
284
|
clear(): void;
|
|
285
|
+
/**
|
|
286
|
+
* Hash the key. this is used to determine which store to use (internal use)
|
|
287
|
+
* @param {string} key - The key to hash
|
|
288
|
+
* @returns {number} - The hash number
|
|
289
|
+
*/
|
|
109
290
|
hashKey(key: string): number;
|
|
291
|
+
/**
|
|
292
|
+
* Get the store based on the key (internal use)
|
|
293
|
+
* @param {string} key - The key to get the store
|
|
294
|
+
* @returns {Map<string, any>} - The store
|
|
295
|
+
*/
|
|
110
296
|
getStore(key: string): Map<string, any>;
|
|
297
|
+
/**
|
|
298
|
+
* Clone the value. This is for internal use
|
|
299
|
+
* @param {any} value - The value to clone
|
|
300
|
+
* @returns {any} - The cloned value
|
|
301
|
+
*/
|
|
111
302
|
clone(value: any): any;
|
|
303
|
+
/**
|
|
304
|
+
* Add to the front of the LRU cache. This is for internal use
|
|
305
|
+
* @param {string} key - The key to add to the front
|
|
306
|
+
* @returns {void}
|
|
307
|
+
*/
|
|
112
308
|
lruAddToFront(key: string): void;
|
|
309
|
+
/**
|
|
310
|
+
* Move to the front of the LRU cache. This is for internal use
|
|
311
|
+
* @param {string} key - The key to move to the front
|
|
312
|
+
* @returns {void}
|
|
313
|
+
*/
|
|
113
314
|
lruMoveToFront(key: string): void;
|
|
315
|
+
/**
|
|
316
|
+
* Resize the LRU cache. This is for internal use
|
|
317
|
+
* @returns {void}
|
|
318
|
+
*/
|
|
114
319
|
lruResize(): void;
|
|
320
|
+
/**
|
|
321
|
+
* Check for expiration. This is for internal use
|
|
322
|
+
* @returns {void}
|
|
323
|
+
*/
|
|
115
324
|
checkExpiration(): void;
|
|
325
|
+
/**
|
|
326
|
+
* Start the interval check. This is for internal use
|
|
327
|
+
* @returns {void}
|
|
328
|
+
*/
|
|
116
329
|
startIntervalCheck(): void;
|
|
330
|
+
/**
|
|
331
|
+
* Stop the interval check. This is for internal use
|
|
332
|
+
* @returns {void}
|
|
333
|
+
*/
|
|
117
334
|
stopIntervalCheck(): void;
|
|
335
|
+
/**
|
|
336
|
+
* Hash the object. This is for internal use
|
|
337
|
+
* @param {any} object - The object to hash
|
|
338
|
+
* @param {string} [algorithm='sha256'] - The algorithm to hash
|
|
339
|
+
* @returns {string} - The hashed string
|
|
340
|
+
*/
|
|
118
341
|
hash(object: any, algorithm?: string): string;
|
|
342
|
+
/**
|
|
343
|
+
* Wrap the function for caching
|
|
344
|
+
* @param {Function} function_ - The function to wrap
|
|
345
|
+
* @param {Object} [options] - The options to wrap
|
|
346
|
+
* @returns {Function} - The wrapped function
|
|
347
|
+
*/
|
|
119
348
|
wrap<T>(function_: (...arguments_: any[]) => T, options?: {
|
|
120
349
|
ttl?: number;
|
|
121
350
|
key?: string;
|
|
@@ -188,34 +417,196 @@ declare class Cacheable extends Hookified {
|
|
|
188
417
|
private _nonBlocking;
|
|
189
418
|
private _ttl?;
|
|
190
419
|
private readonly _stats;
|
|
420
|
+
/**
|
|
421
|
+
* Creates a new cacheable instance
|
|
422
|
+
* @param {CacheableOptions} [options] The options for the cacheable instance
|
|
423
|
+
*/
|
|
191
424
|
constructor(options?: CacheableOptions);
|
|
425
|
+
/**
|
|
426
|
+
* The statistics for the cacheable instance
|
|
427
|
+
* @returns {CacheableStats} The statistics for the cacheable instance
|
|
428
|
+
*/
|
|
192
429
|
get stats(): CacheableStats;
|
|
430
|
+
/**
|
|
431
|
+
* The primary store for the cacheable instance
|
|
432
|
+
* @returns {Keyv} The primary store for the cacheable instance
|
|
433
|
+
*/
|
|
193
434
|
get primary(): Keyv;
|
|
435
|
+
/**
|
|
436
|
+
* Sets the primary store for the cacheable instance
|
|
437
|
+
* @param {Keyv} primary The primary store for the cacheable instance
|
|
438
|
+
*/
|
|
194
439
|
set primary(primary: Keyv);
|
|
440
|
+
/**
|
|
441
|
+
* The secondary store for the cacheable instance
|
|
442
|
+
* @returns {Keyv | undefined} The secondary store for the cacheable instance
|
|
443
|
+
*/
|
|
195
444
|
get secondary(): Keyv | undefined;
|
|
445
|
+
/**
|
|
446
|
+
* Sets the secondary store for the cacheable instance. If it is set to undefined then the secondary store is disabled.
|
|
447
|
+
* @param {Keyv | undefined} secondary The secondary store for the cacheable instance
|
|
448
|
+
* @returns {void}
|
|
449
|
+
*/
|
|
196
450
|
set secondary(secondary: Keyv | undefined);
|
|
451
|
+
/**
|
|
452
|
+
* Gets whether the secondary store is non-blocking mode. It is set to false by default.
|
|
453
|
+
* If it is set to true then the secondary store will not block the primary store.
|
|
454
|
+
*
|
|
455
|
+
* [Learn more about non-blocking mode](https://cacheable.org/docs/cacheable/#non-blocking-operations).
|
|
456
|
+
*
|
|
457
|
+
* @returns {boolean} Whether the cacheable instance is non-blocking
|
|
458
|
+
*/
|
|
197
459
|
get nonBlocking(): boolean;
|
|
460
|
+
/**
|
|
461
|
+
* Sets whether the secondary store is non-blocking mode. It is set to false by default.
|
|
462
|
+
* If it is set to true then the secondary store will not block the primary store.
|
|
463
|
+
*
|
|
464
|
+
* [Learn more about non-blocking mode](https://cacheable.org/docs/cacheable/#non-blocking-operations).
|
|
465
|
+
*
|
|
466
|
+
* @param {boolean} nonBlocking Whether the cacheable instance is non-blocking
|
|
467
|
+
* @returns {void}
|
|
468
|
+
*/
|
|
198
469
|
set nonBlocking(nonBlocking: boolean);
|
|
470
|
+
/**
|
|
471
|
+
* The time-to-live for the cacheable instance and will be used as the default value.
|
|
472
|
+
* can be a number in milliseconds or a human-readable format such as `1s` for 1 second or `1h` for 1 hour
|
|
473
|
+
* or undefined if there is no time-to-live.
|
|
474
|
+
*
|
|
475
|
+
* [Learn more about time-to-live](https://cacheable.org/docs/cacheable/#shorthand-for-time-to-live-ttl).
|
|
476
|
+
*
|
|
477
|
+
* @returns {number | string | undefined} The time-to-live for the cacheable instance in milliseconds, human-readable format or undefined
|
|
478
|
+
* @example
|
|
479
|
+
* ```typescript
|
|
480
|
+
* const cacheable = new Cacheable({ ttl: '1h' });
|
|
481
|
+
* console.log(cacheable.ttl); // 1h
|
|
482
|
+
* ```
|
|
483
|
+
*/
|
|
199
484
|
get ttl(): number | string | undefined;
|
|
485
|
+
/**
|
|
486
|
+
* Sets the time-to-live for the cacheable instance and will be used as the default value.
|
|
487
|
+
* If you set a number it is miliseconds, if you set a string it is a human-readable
|
|
488
|
+
* format such as `1s` for 1 second or `1h` for 1 hour. Setting undefined means that
|
|
489
|
+
* there is no time-to-live.
|
|
490
|
+
*
|
|
491
|
+
* [Learn more about time-to-live](https://cacheable.org/docs/cacheable/#shorthand-for-time-to-live-ttl).
|
|
492
|
+
*
|
|
493
|
+
* @param {number | string | undefined} ttl The time-to-live for the cacheable instance
|
|
494
|
+
* @example
|
|
495
|
+
* ```typescript
|
|
496
|
+
* const cacheable = new Cacheable();
|
|
497
|
+
* cacheable.ttl = '1h'; // Set the time-to-live to 1 hour
|
|
498
|
+
* ```
|
|
499
|
+
* or setting the time-to-live in milliseconds
|
|
500
|
+
* ```typescript
|
|
501
|
+
* const cacheable = new Cacheable();
|
|
502
|
+
* cacheable.ttl = 3600000; // Set the time-to-live to 1 hour
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
200
505
|
set ttl(ttl: number | string | undefined);
|
|
506
|
+
/**
|
|
507
|
+
* Sets the primary store for the cacheable instance
|
|
508
|
+
* @param {Keyv | KeyvStoreAdapter} primary The primary store for the cacheable instance
|
|
509
|
+
* @returns {void}
|
|
510
|
+
*/
|
|
201
511
|
setPrimary(primary: Keyv | KeyvStoreAdapter): void;
|
|
512
|
+
/**
|
|
513
|
+
* Sets the secondary store for the cacheable instance. If it is set to undefined then the secondary store is disabled.
|
|
514
|
+
* @param {Keyv | KeyvStoreAdapter} secondary The secondary store for the cacheable instance
|
|
515
|
+
* @returns {void}
|
|
516
|
+
*/
|
|
202
517
|
setSecondary(secondary: Keyv | KeyvStoreAdapter): void;
|
|
518
|
+
/**
|
|
519
|
+
* Gets the value of the key. If the key does not exist in the primary store then it will check the secondary store.
|
|
520
|
+
* @param {string} key The key to get the value of
|
|
521
|
+
* @returns {Promise<T | undefined>} The value of the key or undefined if the key does not exist
|
|
522
|
+
*/
|
|
203
523
|
get<T>(key: string): Promise<T | undefined>;
|
|
524
|
+
/**
|
|
525
|
+
* Gets the values of the keys. If the key does not exist in the primary store then it will check the secondary store.
|
|
526
|
+
* @param {string[]} keys The keys to get the values of
|
|
527
|
+
* @returns {Promise<Array<T | undefined>>} The values of the keys or undefined if the key does not exist
|
|
528
|
+
*/
|
|
204
529
|
getMany<T>(keys: string[]): Promise<Array<T | undefined>>;
|
|
530
|
+
/**
|
|
531
|
+
* Sets the value of the key. If the secondary store is set then it will also set the value in the secondary store.
|
|
532
|
+
* @param {string} key the key to set the value of
|
|
533
|
+
* @param {T} value The value to set
|
|
534
|
+
* @param {number | string} [ttl] Time to Live - If you set a number it is miliseconds, if you set a string it is a human-readable
|
|
535
|
+
* format such as `1s` for 1 second or `1h` for 1 hour. Setting undefined means that it will use the default time-to-live. If both are
|
|
536
|
+
* undefined then it will not have a time-to-live.
|
|
537
|
+
* @returns {boolean} Whether the value was set
|
|
538
|
+
*/
|
|
205
539
|
set<T>(key: string, value: T, ttl?: number | string): Promise<boolean>;
|
|
540
|
+
/**
|
|
541
|
+
* Sets the values of the keys. If the secondary store is set then it will also set the values in the secondary store.
|
|
542
|
+
* @param {CacheableItem[]} items The items to set
|
|
543
|
+
* @returns {boolean} Whether the values were set
|
|
544
|
+
*/
|
|
206
545
|
setMany(items: CacheableItem[]): Promise<boolean>;
|
|
546
|
+
/**
|
|
547
|
+
* Takes the value of the key and deletes the key. If the key does not exist then it will return undefined.
|
|
548
|
+
* @param {string} key The key to take the value of
|
|
549
|
+
* @returns {Promise<T | undefined>} The value of the key or undefined if the key does not exist
|
|
550
|
+
*/
|
|
207
551
|
take<T>(key: string): Promise<T | undefined>;
|
|
552
|
+
/**
|
|
553
|
+
* Takes the values of the keys and deletes the keys. If the key does not exist then it will return undefined.
|
|
554
|
+
* @param {string[]} keys The keys to take the values of
|
|
555
|
+
* @returns {Promise<Array<T | undefined>>} The values of the keys or undefined if the key does not exist
|
|
556
|
+
*/
|
|
208
557
|
takeMany<T>(keys: string[]): Promise<Array<T | undefined>>;
|
|
558
|
+
/**
|
|
559
|
+
* Checks if the key exists in the primary store. If it does not exist then it will check the secondary store.
|
|
560
|
+
* @param {string} key The key to check
|
|
561
|
+
* @returns {Promise<boolean>} Whether the key exists
|
|
562
|
+
*/
|
|
209
563
|
has(key: string): Promise<boolean>;
|
|
564
|
+
/**
|
|
565
|
+
* Checks if the keys exist in the primary store. If it does not exist then it will check the secondary store.
|
|
566
|
+
* @param {string[]} keys The keys to check
|
|
567
|
+
* @returns {Promise<boolean[]>} Whether the keys exist
|
|
568
|
+
*/
|
|
210
569
|
hasMany(keys: string[]): Promise<boolean[]>;
|
|
570
|
+
/**
|
|
571
|
+
* Deletes the key from the primary store. If the secondary store is set then it will also delete the key from the secondary store.
|
|
572
|
+
* @param {string} key The key to delete
|
|
573
|
+
* @returns {Promise<boolean>} Whether the key was deleted
|
|
574
|
+
*/
|
|
211
575
|
delete(key: string): Promise<boolean>;
|
|
576
|
+
/**
|
|
577
|
+
* Deletes the keys from the primary store. If the secondary store is set then it will also delete the keys from the secondary store.
|
|
578
|
+
* @param {string[]} keys The keys to delete
|
|
579
|
+
* @returns {Promise<boolean>} Whether the keys were deleted
|
|
580
|
+
*/
|
|
212
581
|
deleteMany(keys: string[]): Promise<boolean>;
|
|
582
|
+
/**
|
|
583
|
+
* Clears the primary store. If the secondary store is set then it will also clear the secondary store.
|
|
584
|
+
* @returns {Promise<void>}
|
|
585
|
+
*/
|
|
213
586
|
clear(): Promise<void>;
|
|
587
|
+
/**
|
|
588
|
+
* Disconnects the primary store. If the secondary store is set then it will also disconnect the secondary store.
|
|
589
|
+
* @returns {Promise<void>}
|
|
590
|
+
*/
|
|
214
591
|
disconnect(): Promise<void>;
|
|
592
|
+
/**
|
|
593
|
+
* Wraps a function with caching
|
|
594
|
+
*
|
|
595
|
+
* [Learn more about wrapping functions](https://cacheable.org/docs/cacheable/#wrap--memoization-for-sync-and-async-functions).
|
|
596
|
+
* @param {Function} function_ The function to wrap
|
|
597
|
+
* @param {WrapOptions} [options] The options for the wrap function
|
|
598
|
+
* @returns {Function} The wrapped function
|
|
599
|
+
*/
|
|
215
600
|
wrap<T>(function_: (...arguments_: any[]) => T, options?: {
|
|
216
601
|
ttl?: number;
|
|
217
602
|
key?: string;
|
|
218
603
|
}): (...arguments_: any[]) => T;
|
|
604
|
+
/**
|
|
605
|
+
* Will hash an object using the specified algorithm. The default algorithm is 'sha256'.
|
|
606
|
+
* @param {any} object the object to hash
|
|
607
|
+
* @param {string} algorithm the hash algorithm to use. The default is 'sha256'
|
|
608
|
+
* @returns {string} the hash of the object
|
|
609
|
+
*/
|
|
219
610
|
hash(object: any, algorithm?: string): string;
|
|
220
611
|
private deleteManyKeyv;
|
|
221
612
|
private setManyKeyv;
|