cacheable 1.10.3 → 2.0.0
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 +58 -159
- package/dist/index.cjs +1 -1865
- package/dist/index.d.cts +120 -503
- package/dist/index.d.ts +120 -503
- package/dist/index.js +1 -1822
- package/package.json +16 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,462 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { WrapFunctionOptions, GetOrSetKey, GetOrSetFunctionOptions } from '@cacheable/memoize';
|
|
2
|
+
export { GetOrSetFunctionOptions, GetOrSetKey, GetOrSetOptions, WrapOptions, WrapSyncOptions, getOrSet, wrap, wrapSync } from '@cacheable/memoize';
|
|
3
|
+
import { Stats, CacheableItem, HashAlgorithm } from '@cacheable/utils';
|
|
4
|
+
export { CacheableItem, Stats as CacheableStats, HashAlgorithm, calculateTtlFromExpiration, getCascadingTtl, hash, shorthandToMilliseconds, shorthandToTime } from '@cacheable/utils';
|
|
3
5
|
import { Hookified } from 'hookified';
|
|
6
|
+
import { Keyv, KeyvStoreAdapter, StoredDataRaw } from 'keyv';
|
|
7
|
+
export { Keyv, KeyvHooks, KeyvOptions, KeyvStoreAdapter } from 'keyv';
|
|
8
|
+
export { CacheableMemory, CacheableMemoryOptions, KeyvCacheableMemory, KeyvCacheableMemoryOptions, createKeyv } from '@cacheable/memory';
|
|
4
9
|
|
|
5
|
-
type CacheableOptions$1 = {
|
|
6
|
-
enabled?: boolean;
|
|
7
|
-
};
|
|
8
|
-
declare class CacheableStats {
|
|
9
|
-
private _hits;
|
|
10
|
-
private _misses;
|
|
11
|
-
private _gets;
|
|
12
|
-
private _sets;
|
|
13
|
-
private _deletes;
|
|
14
|
-
private _clears;
|
|
15
|
-
private _vsize;
|
|
16
|
-
private _ksize;
|
|
17
|
-
private _count;
|
|
18
|
-
private _enabled;
|
|
19
|
-
constructor(options?: CacheableOptions$1);
|
|
20
|
-
/**
|
|
21
|
-
* @returns {boolean} - Whether the stats are enabled
|
|
22
|
-
*/
|
|
23
|
-
get enabled(): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* @param {boolean} enabled - Whether to enable the stats
|
|
26
|
-
*/
|
|
27
|
-
set enabled(enabled: boolean);
|
|
28
|
-
/**
|
|
29
|
-
* @returns {number} - The number of hits
|
|
30
|
-
* @readonly
|
|
31
|
-
*/
|
|
32
|
-
get hits(): number;
|
|
33
|
-
/**
|
|
34
|
-
* @returns {number} - The number of misses
|
|
35
|
-
* @readonly
|
|
36
|
-
*/
|
|
37
|
-
get misses(): number;
|
|
38
|
-
/**
|
|
39
|
-
* @returns {number} - The number of gets
|
|
40
|
-
* @readonly
|
|
41
|
-
*/
|
|
42
|
-
get gets(): number;
|
|
43
|
-
/**
|
|
44
|
-
* @returns {number} - The number of sets
|
|
45
|
-
* @readonly
|
|
46
|
-
*/
|
|
47
|
-
get sets(): number;
|
|
48
|
-
/**
|
|
49
|
-
* @returns {number} - The number of deletes
|
|
50
|
-
* @readonly
|
|
51
|
-
*/
|
|
52
|
-
get deletes(): number;
|
|
53
|
-
/**
|
|
54
|
-
* @returns {number} - The number of clears
|
|
55
|
-
* @readonly
|
|
56
|
-
*/
|
|
57
|
-
get clears(): number;
|
|
58
|
-
/**
|
|
59
|
-
* @returns {number} - The vsize (value size) of the cache instance
|
|
60
|
-
* @readonly
|
|
61
|
-
*/
|
|
62
|
-
get vsize(): number;
|
|
63
|
-
/**
|
|
64
|
-
* @returns {number} - The ksize (key size) of the cache instance
|
|
65
|
-
* @readonly
|
|
66
|
-
*/
|
|
67
|
-
get ksize(): number;
|
|
68
|
-
/**
|
|
69
|
-
* @returns {number} - The count of the cache instance
|
|
70
|
-
* @readonly
|
|
71
|
-
*/
|
|
72
|
-
get count(): number;
|
|
73
|
-
incrementHits(): void;
|
|
74
|
-
incrementMisses(): void;
|
|
75
|
-
incrementGets(): void;
|
|
76
|
-
incrementSets(): void;
|
|
77
|
-
incrementDeletes(): void;
|
|
78
|
-
incrementClears(): void;
|
|
79
|
-
incrementVSize(value: any): void;
|
|
80
|
-
decreaseVSize(value: any): void;
|
|
81
|
-
incrementKSize(key: string): void;
|
|
82
|
-
decreaseKSize(key: string): void;
|
|
83
|
-
incrementCount(): void;
|
|
84
|
-
decreaseCount(): void;
|
|
85
|
-
setCount(count: number): void;
|
|
86
|
-
roughSizeOfString(value: string): number;
|
|
87
|
-
roughSizeOfObject(object: any): number;
|
|
88
|
-
reset(): void;
|
|
89
|
-
resetStoreValues(): void;
|
|
90
|
-
}
|
|
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
|
-
*/
|
|
101
|
-
type CacheableItem = {
|
|
102
|
-
key: string;
|
|
103
|
-
value: any;
|
|
104
|
-
ttl?: number | string;
|
|
105
|
-
};
|
|
106
|
-
type CacheableStoreItem = {
|
|
107
|
-
key: string;
|
|
108
|
-
value: any;
|
|
109
|
-
expires?: number;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
type GetOrSetKey = string | ((options?: GetOrSetOptions) => string);
|
|
113
|
-
type GetOrSetFunctionOptions = {
|
|
114
|
-
ttl?: number | string;
|
|
115
|
-
cacheErrors?: boolean;
|
|
116
|
-
throwErrors?: boolean;
|
|
117
|
-
};
|
|
118
|
-
type GetOrSetOptions = GetOrSetFunctionOptions & {
|
|
119
|
-
cacheId?: string;
|
|
120
|
-
cache: Cacheable;
|
|
121
|
-
};
|
|
122
|
-
type CreateWrapKey = (function_: AnyFunction, arguments_: any[], options?: WrapFunctionOptions) => string;
|
|
123
|
-
type WrapFunctionOptions = {
|
|
124
|
-
ttl?: number | string;
|
|
125
|
-
keyPrefix?: string;
|
|
126
|
-
createKey?: CreateWrapKey;
|
|
127
|
-
cacheErrors?: boolean;
|
|
128
|
-
cacheId?: string;
|
|
129
|
-
};
|
|
130
|
-
type WrapOptions = WrapFunctionOptions & {
|
|
131
|
-
cache: Cacheable;
|
|
132
|
-
};
|
|
133
|
-
type WrapSyncOptions = WrapFunctionOptions & {
|
|
134
|
-
cache: CacheableMemory;
|
|
135
|
-
};
|
|
136
|
-
type AnyFunction = (...arguments_: any[]) => any;
|
|
137
|
-
declare function wrapSync<T>(function_: AnyFunction, options: WrapSyncOptions): AnyFunction;
|
|
138
|
-
declare function getOrSet<T>(key: GetOrSetKey, function_: () => Promise<T>, options: GetOrSetOptions): Promise<T | undefined>;
|
|
139
|
-
declare function wrap<T>(function_: AnyFunction, options: WrapOptions): AnyFunction;
|
|
140
|
-
|
|
141
|
-
declare enum StoreHashAlgorithm {
|
|
142
|
-
SHA256 = "sha256",
|
|
143
|
-
SHA1 = "sha1",
|
|
144
|
-
MD5 = "md5",
|
|
145
|
-
djb2Hash = "djb2Hash"
|
|
146
|
-
}
|
|
147
|
-
type StoreHashAlgorithmFunction = ((key: string, storeHashSize: number) => number);
|
|
148
|
-
/**
|
|
149
|
-
* @typedef {Object} CacheableMemoryOptions
|
|
150
|
-
* @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
|
|
151
|
-
* 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
|
|
152
|
-
* undefined then it will not have a time-to-live.
|
|
153
|
-
* @property {boolean} [useClone] - If true, it will clone the value before returning it. If false, it will return the value directly. Default is true.
|
|
154
|
-
* @property {number} [lruSize] - The size of the LRU cache. If set to 0, it will not use LRU cache. Default is 0. If you are using LRU then the limit is based on Map() size 17mm.
|
|
155
|
-
* @property {number} [checkInterval] - The interval to check for expired items. If set to 0, it will not check for expired items. Default is 0.
|
|
156
|
-
* @property {number} [storeHashSize] - The number of how many Map stores we have for the hash. Default is 10.
|
|
157
|
-
*/
|
|
158
|
-
type CacheableMemoryOptions = {
|
|
159
|
-
ttl?: number | string;
|
|
160
|
-
useClone?: boolean;
|
|
161
|
-
lruSize?: number;
|
|
162
|
-
checkInterval?: number;
|
|
163
|
-
storeHashSize?: number;
|
|
164
|
-
storeHashAlgorithm?: StoreHashAlgorithm | ((key: string, storeHashSize: number) => number);
|
|
165
|
-
};
|
|
166
|
-
type SetOptions = {
|
|
167
|
-
ttl?: number | string;
|
|
168
|
-
expire?: number | Date;
|
|
169
|
-
};
|
|
170
|
-
declare class CacheableMemory extends Hookified {
|
|
171
|
-
private _lru;
|
|
172
|
-
private _storeHashSize;
|
|
173
|
-
private _storeHashAlgorithm;
|
|
174
|
-
private _store;
|
|
175
|
-
private _ttl;
|
|
176
|
-
private _useClone;
|
|
177
|
-
private _lruSize;
|
|
178
|
-
private _checkInterval;
|
|
179
|
-
private _interval;
|
|
180
|
-
/**
|
|
181
|
-
* @constructor
|
|
182
|
-
* @param {CacheableMemoryOptions} [options] - The options for the CacheableMemory
|
|
183
|
-
*/
|
|
184
|
-
constructor(options?: CacheableMemoryOptions);
|
|
185
|
-
/**
|
|
186
|
-
* Gets the time-to-live
|
|
187
|
-
* @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.
|
|
188
|
-
*/
|
|
189
|
-
get ttl(): number | string | undefined;
|
|
190
|
-
/**
|
|
191
|
-
* Sets the time-to-live
|
|
192
|
-
* @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.
|
|
193
|
-
*/
|
|
194
|
-
set ttl(value: number | string | undefined);
|
|
195
|
-
/**
|
|
196
|
-
* Gets whether to use clone
|
|
197
|
-
* @returns {boolean} - If true, it will clone the value before returning it. If false, it will return the value directly. Default is true.
|
|
198
|
-
*/
|
|
199
|
-
get useClone(): boolean;
|
|
200
|
-
/**
|
|
201
|
-
* Sets whether to use clone
|
|
202
|
-
* @param {boolean} value - If true, it will clone the value before returning it. If false, it will return the value directly. Default is true.
|
|
203
|
-
*/
|
|
204
|
-
set useClone(value: boolean);
|
|
205
|
-
/**
|
|
206
|
-
* Gets the size of the LRU cache
|
|
207
|
-
* @returns {number} - The size of the LRU cache. If set to 0, it will not use LRU cache. Default is 0. If you are using LRU then the limit is based on Map() size 17mm.
|
|
208
|
-
*/
|
|
209
|
-
get lruSize(): number;
|
|
210
|
-
/**
|
|
211
|
-
* Sets the size of the LRU cache
|
|
212
|
-
* @param {number} value - The size of the LRU cache. If set to 0, it will not use LRU cache. Default is 0. If you are using LRU then the limit is based on Map() size 17mm.
|
|
213
|
-
*/
|
|
214
|
-
set lruSize(value: number);
|
|
215
|
-
/**
|
|
216
|
-
* Gets the check interval
|
|
217
|
-
* @returns {number} - The interval to check for expired items. If set to 0, it will not check for expired items. Default is 0.
|
|
218
|
-
*/
|
|
219
|
-
get checkInterval(): number;
|
|
220
|
-
/**
|
|
221
|
-
* Sets the check interval
|
|
222
|
-
* @param {number} value - The interval to check for expired items. If set to 0, it will not check for expired items. Default is 0.
|
|
223
|
-
*/
|
|
224
|
-
set checkInterval(value: number);
|
|
225
|
-
/**
|
|
226
|
-
* Gets the size of the cache
|
|
227
|
-
* @returns {number} - The size of the cache
|
|
228
|
-
*/
|
|
229
|
-
get size(): number;
|
|
230
|
-
/**
|
|
231
|
-
* Gets the number of hash stores
|
|
232
|
-
* @returns {number} - The number of hash stores
|
|
233
|
-
*/
|
|
234
|
-
get storeHashSize(): number;
|
|
235
|
-
/**
|
|
236
|
-
* Sets the number of hash stores. This will recreate the store and all data will be cleared
|
|
237
|
-
* @param {number} value - The number of hash stores
|
|
238
|
-
*/
|
|
239
|
-
set storeHashSize(value: number);
|
|
240
|
-
/**
|
|
241
|
-
* Gets the store hash algorithm
|
|
242
|
-
* @returns {StoreHashAlgorithm | StoreHashAlgorithmFunction} - The store hash algorithm
|
|
243
|
-
*/
|
|
244
|
-
get storeHashAlgorithm(): StoreHashAlgorithm | StoreHashAlgorithmFunction;
|
|
245
|
-
/**
|
|
246
|
-
* Sets the store hash algorithm. This will recreate the store and all data will be cleared
|
|
247
|
-
* @param {StoreHashAlgorithm | StoreHashAlgorithmFunction} value - The store hash algorithm
|
|
248
|
-
*/
|
|
249
|
-
set storeHashAlgorithm(value: StoreHashAlgorithm | StoreHashAlgorithmFunction);
|
|
250
|
-
/**
|
|
251
|
-
* Gets the keys
|
|
252
|
-
* @returns {IterableIterator<string>} - The keys
|
|
253
|
-
*/
|
|
254
|
-
get keys(): IterableIterator<string>;
|
|
255
|
-
/**
|
|
256
|
-
* Gets the items
|
|
257
|
-
* @returns {IterableIterator<CacheableStoreItem>} - The items
|
|
258
|
-
*/
|
|
259
|
-
get items(): IterableIterator<CacheableStoreItem>;
|
|
260
|
-
/**
|
|
261
|
-
* Gets the store
|
|
262
|
-
* @returns {Array<Map<string, CacheableStoreItem>>} - The store
|
|
263
|
-
*/
|
|
264
|
-
get store(): Array<Map<string, CacheableStoreItem>>;
|
|
265
|
-
/**
|
|
266
|
-
* Gets the value of the key
|
|
267
|
-
* @param {string} key - The key to get the value
|
|
268
|
-
* @returns {T | undefined} - The value of the key
|
|
269
|
-
*/
|
|
270
|
-
get<T>(key: string): T | undefined;
|
|
271
|
-
/**
|
|
272
|
-
* Gets the values of the keys
|
|
273
|
-
* @param {string[]} keys - The keys to get the values
|
|
274
|
-
* @returns {T[]} - The values of the keys
|
|
275
|
-
*/
|
|
276
|
-
getMany<T>(keys: string[]): T[];
|
|
277
|
-
/**
|
|
278
|
-
* Gets the raw value of the key
|
|
279
|
-
* @param {string} key - The key to get the value
|
|
280
|
-
* @returns {CacheableStoreItem | undefined} - The raw value of the key
|
|
281
|
-
*/
|
|
282
|
-
getRaw(key: string): CacheableStoreItem | undefined;
|
|
283
|
-
/**
|
|
284
|
-
* Gets the raw values of the keys
|
|
285
|
-
* @param {string[]} keys - The keys to get the values
|
|
286
|
-
* @returns {CacheableStoreItem[]} - The raw values of the keys
|
|
287
|
-
*/
|
|
288
|
-
getManyRaw(keys: string[]): Array<CacheableStoreItem | undefined>;
|
|
289
|
-
/**
|
|
290
|
-
* Sets the value of the key
|
|
291
|
-
* @param {string} key - The key to set the value
|
|
292
|
-
* @param {any} value - The value to set
|
|
293
|
-
* @param {number|string|SetOptions} [ttl] - Time to Live - If you set a number it is miliseconds, if you set a string it is a human-readable.
|
|
294
|
-
* If you want to set expire directly you can do that by setting the expire property in the SetOptions.
|
|
295
|
-
* 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.
|
|
296
|
-
* @returns {void}
|
|
297
|
-
*/
|
|
298
|
-
set(key: string, value: any, ttl?: number | string | SetOptions): void;
|
|
299
|
-
/**
|
|
300
|
-
* Sets the values of the keys
|
|
301
|
-
* @param {CacheableItem[]} items - The items to set
|
|
302
|
-
* @returns {void}
|
|
303
|
-
*/
|
|
304
|
-
setMany(items: CacheableItem[]): void;
|
|
305
|
-
/**
|
|
306
|
-
* Checks if the key exists
|
|
307
|
-
* @param {string} key - The key to check
|
|
308
|
-
* @returns {boolean} - If true, the key exists. If false, the key does not exist.
|
|
309
|
-
*/
|
|
310
|
-
has(key: string): boolean;
|
|
311
|
-
/**
|
|
312
|
-
* @function hasMany
|
|
313
|
-
* @param {string[]} keys - The keys to check
|
|
314
|
-
* @returns {boolean[]} - If true, the key exists. If false, the key does not exist.
|
|
315
|
-
*/
|
|
316
|
-
hasMany(keys: string[]): boolean[];
|
|
317
|
-
/**
|
|
318
|
-
* Take will get the key and delete the entry from cache
|
|
319
|
-
* @param {string} key - The key to take
|
|
320
|
-
* @returns {T | undefined} - The value of the key
|
|
321
|
-
*/
|
|
322
|
-
take<T>(key: string): T | undefined;
|
|
323
|
-
/**
|
|
324
|
-
* TakeMany will get the keys and delete the entries from cache
|
|
325
|
-
* @param {string[]} keys - The keys to take
|
|
326
|
-
* @returns {T[]} - The values of the keys
|
|
327
|
-
*/
|
|
328
|
-
takeMany<T>(keys: string[]): T[];
|
|
329
|
-
/**
|
|
330
|
-
* Delete the key
|
|
331
|
-
* @param {string} key - The key to delete
|
|
332
|
-
* @returns {void}
|
|
333
|
-
*/
|
|
334
|
-
delete(key: string): void;
|
|
335
|
-
/**
|
|
336
|
-
* Delete the keys
|
|
337
|
-
* @param {string[]} keys - The keys to delete
|
|
338
|
-
* @returns {void}
|
|
339
|
-
*/
|
|
340
|
-
deleteMany(keys: string[]): void;
|
|
341
|
-
/**
|
|
342
|
-
* Clear the cache
|
|
343
|
-
* @returns {void}
|
|
344
|
-
*/
|
|
345
|
-
clear(): void;
|
|
346
|
-
/**
|
|
347
|
-
* Get the store based on the key (internal use)
|
|
348
|
-
* @param {string} key - The key to get the store
|
|
349
|
-
* @returns {CacheableHashStore} - The store
|
|
350
|
-
*/
|
|
351
|
-
getStore(key: string): Map<string, CacheableStoreItem>;
|
|
352
|
-
/**
|
|
353
|
-
* Hash the key for which store to go to (internal use)
|
|
354
|
-
* @param {string} key - The key to hash
|
|
355
|
-
* Available algorithms are: SHA256, SHA1, MD5, and djb2Hash.
|
|
356
|
-
* @returns {number} - The hashed key as a number
|
|
357
|
-
*/
|
|
358
|
-
getKeyStoreHash(key: string): number;
|
|
359
|
-
/**
|
|
360
|
-
* Clone the value. This is for internal use
|
|
361
|
-
* @param {any} value - The value to clone
|
|
362
|
-
* @returns {any} - The cloned value
|
|
363
|
-
*/
|
|
364
|
-
clone(value: any): any;
|
|
365
|
-
/**
|
|
366
|
-
* Add to the front of the LRU cache. This is for internal use
|
|
367
|
-
* @param {string} key - The key to add to the front
|
|
368
|
-
* @returns {void}
|
|
369
|
-
*/
|
|
370
|
-
lruAddToFront(key: string): void;
|
|
371
|
-
/**
|
|
372
|
-
* Move to the front of the LRU cache. This is for internal use
|
|
373
|
-
* @param {string} key - The key to move to the front
|
|
374
|
-
* @returns {void}
|
|
375
|
-
*/
|
|
376
|
-
lruMoveToFront(key: string): void;
|
|
377
|
-
/**
|
|
378
|
-
* Resize the LRU cache. This is for internal use.
|
|
379
|
-
* @returns {void}
|
|
380
|
-
*/
|
|
381
|
-
lruResize(): void;
|
|
382
|
-
/**
|
|
383
|
-
* Check for expiration. This is for internal use
|
|
384
|
-
* @returns {void}
|
|
385
|
-
*/
|
|
386
|
-
checkExpiration(): void;
|
|
387
|
-
/**
|
|
388
|
-
* Start the interval check. This is for internal use
|
|
389
|
-
* @returns {void}
|
|
390
|
-
*/
|
|
391
|
-
startIntervalCheck(): void;
|
|
392
|
-
/**
|
|
393
|
-
* Stop the interval check. This is for internal use
|
|
394
|
-
* @returns {void}
|
|
395
|
-
*/
|
|
396
|
-
stopIntervalCheck(): void;
|
|
397
|
-
/**
|
|
398
|
-
* Wrap the function for caching
|
|
399
|
-
* @param {Function} function_ - The function to wrap
|
|
400
|
-
* @param {Object} [options] - The options to wrap
|
|
401
|
-
* @returns {Function} - The wrapped function
|
|
402
|
-
*/
|
|
403
|
-
wrap<T, Arguments extends any[]>(function_: (...arguments_: Arguments) => T, options?: WrapFunctionOptions): (...arguments_: Arguments) => T;
|
|
404
|
-
private isPrimitive;
|
|
405
|
-
private setTtl;
|
|
406
|
-
private hasExpired;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
type KeyvCacheableMemoryOptions = CacheableMemoryOptions & {
|
|
410
|
-
namespace?: string;
|
|
411
|
-
};
|
|
412
|
-
declare class KeyvCacheableMemory implements KeyvStoreAdapter {
|
|
413
|
-
opts: CacheableMemoryOptions;
|
|
414
|
-
private readonly _defaultCache;
|
|
415
|
-
private readonly _nCache;
|
|
416
|
-
private _namespace?;
|
|
417
|
-
constructor(options?: KeyvCacheableMemoryOptions);
|
|
418
|
-
get namespace(): string | undefined;
|
|
419
|
-
set namespace(value: string | undefined);
|
|
420
|
-
get store(): CacheableMemory;
|
|
421
|
-
get<Value>(key: string): Promise<StoredData<Value> | undefined>;
|
|
422
|
-
getMany<Value>(keys: string[]): Promise<Array<StoredData<Value | undefined>>>;
|
|
423
|
-
set(key: string, value: any, ttl?: number): Promise<void>;
|
|
424
|
-
setMany(values: Array<{
|
|
425
|
-
key: string;
|
|
426
|
-
value: any;
|
|
427
|
-
ttl?: number;
|
|
428
|
-
}>): Promise<void>;
|
|
429
|
-
delete(key: string): Promise<boolean>;
|
|
430
|
-
deleteMany?(key: string[]): Promise<boolean>;
|
|
431
|
-
clear(): Promise<void>;
|
|
432
|
-
has?(key: string): Promise<boolean>;
|
|
433
|
-
on(event: string, listener: (...arguments_: any[]) => void): this;
|
|
434
|
-
getStore(namespace?: string): CacheableMemory;
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Creates a new Keyv instance with a new KeyvCacheableMemory store. This also removes the serialize/deserialize methods from the Keyv instance for optimization.
|
|
438
|
-
* @param options
|
|
439
|
-
* @returns
|
|
440
|
-
*/
|
|
441
|
-
declare function createKeyv(options?: KeyvCacheableMemoryOptions): Keyv;
|
|
442
|
-
|
|
443
|
-
declare const shorthandToMilliseconds: (shorthand?: string | number) => number | undefined;
|
|
444
|
-
declare const shorthandToTime: (shorthand?: string | number, fromDate?: Date) => number;
|
|
445
|
-
|
|
446
|
-
declare enum CacheableHooks {
|
|
447
|
-
BEFORE_SET = "BEFORE_SET",
|
|
448
|
-
AFTER_SET = "AFTER_SET",
|
|
449
|
-
BEFORE_SET_MANY = "BEFORE_SET_MANY",
|
|
450
|
-
AFTER_SET_MANY = "AFTER_SET_MANY",
|
|
451
|
-
BEFORE_GET = "BEFORE_GET",
|
|
452
|
-
AFTER_GET = "AFTER_GET",
|
|
453
|
-
BEFORE_GET_MANY = "BEFORE_GET_MANY",
|
|
454
|
-
AFTER_GET_MANY = "AFTER_GET_MANY",
|
|
455
|
-
BEFORE_SECONDARY_SETS_PRIMARY = "BEFORE_SECONDARY_SETS_PRIMARY"
|
|
456
|
-
}
|
|
457
|
-
declare enum CacheableEvents {
|
|
458
|
-
ERROR = "error"
|
|
459
|
-
}
|
|
460
10
|
type CacheableOptions = {
|
|
461
11
|
/**
|
|
462
12
|
* The primary store for the cacheable instance
|
|
@@ -491,6 +41,31 @@ type CacheableOptions = {
|
|
|
491
41
|
*/
|
|
492
42
|
cacheId?: string;
|
|
493
43
|
};
|
|
44
|
+
type GetOptions = {
|
|
45
|
+
/**
|
|
46
|
+
* If set, this will bypass the instances nonBlocking setting.
|
|
47
|
+
* @type {boolean}
|
|
48
|
+
*/
|
|
49
|
+
nonBlocking?: boolean;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
declare enum CacheableHooks {
|
|
53
|
+
BEFORE_SET = "BEFORE_SET",
|
|
54
|
+
AFTER_SET = "AFTER_SET",
|
|
55
|
+
BEFORE_SET_MANY = "BEFORE_SET_MANY",
|
|
56
|
+
AFTER_SET_MANY = "AFTER_SET_MANY",
|
|
57
|
+
BEFORE_GET = "BEFORE_GET",
|
|
58
|
+
AFTER_GET = "AFTER_GET",
|
|
59
|
+
BEFORE_GET_MANY = "BEFORE_GET_MANY",
|
|
60
|
+
AFTER_GET_MANY = "AFTER_GET_MANY",
|
|
61
|
+
BEFORE_SECONDARY_SETS_PRIMARY = "BEFORE_SECONDARY_SETS_PRIMARY"
|
|
62
|
+
}
|
|
63
|
+
declare enum CacheableEvents {
|
|
64
|
+
ERROR = "error",
|
|
65
|
+
CACHE_HIT = "cache:hit",
|
|
66
|
+
CACHE_MISS = "cache:miss"
|
|
67
|
+
}
|
|
68
|
+
|
|
494
69
|
declare class Cacheable extends Hookified {
|
|
495
70
|
private _primary;
|
|
496
71
|
private _secondary;
|
|
@@ -519,7 +94,7 @@ declare class Cacheable extends Hookified {
|
|
|
519
94
|
* The statistics for the cacheable instance
|
|
520
95
|
* @returns {CacheableStats} The statistics for the cacheable instance
|
|
521
96
|
*/
|
|
522
|
-
get stats():
|
|
97
|
+
get stats(): Stats;
|
|
523
98
|
/**
|
|
524
99
|
* The primary store for the cacheable instance
|
|
525
100
|
* @returns {Keyv} The primary store for the cacheable instance
|
|
@@ -623,46 +198,56 @@ declare class Cacheable extends Hookified {
|
|
|
623
198
|
isKeyvInstance(keyv: any): boolean;
|
|
624
199
|
getNameSpace(): string | undefined;
|
|
625
200
|
/**
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
201
|
+
* Retrieves an entry from the cache.
|
|
202
|
+
*
|
|
203
|
+
* Checks the primary store first; if not found and a secondary store is configured,
|
|
204
|
+
* it will fetch from the secondary, repopulate the primary, and return the result.
|
|
205
|
+
*
|
|
206
|
+
* @typeParam T - The expected type of the stored value.
|
|
207
|
+
* @param {string} key - The cache key to retrieve.
|
|
208
|
+
* @param {GetOptions} - options such as to bypass `nonBlocking` for this call
|
|
209
|
+
* @returns {Promise<T | undefined>}
|
|
210
|
+
* A promise that resolves to the cached value if found, or `undefined`.
|
|
211
|
+
*/
|
|
212
|
+
get<T>(key: string, options?: GetOptions): Promise<T | undefined>;
|
|
213
|
+
/**
|
|
214
|
+
* Retrieves the raw entry from the cache including metadata like expiration.
|
|
215
|
+
*
|
|
216
|
+
* Checks the primary store first; if not found and a secondary store is configured,
|
|
217
|
+
* it will fetch from the secondary, repopulate the primary, and return the result.
|
|
218
|
+
*
|
|
219
|
+
* @typeParam T - The expected type of the stored value.
|
|
220
|
+
* @param {string} key - The cache key to retrieve.
|
|
221
|
+
* @param {GetOptions} - options such as to bypass `nonBlocking` for this call
|
|
222
|
+
* @returns {Promise<StoredDataRaw<T>>}
|
|
223
|
+
* A promise that resolves to the full raw data object if found, or undefined.
|
|
224
|
+
*/
|
|
225
|
+
getRaw<T>(key: string, options?: GetOptions): Promise<StoredDataRaw<T>>;
|
|
226
|
+
/**
|
|
227
|
+
* Retrieves multiple raw entries from the cache including metadata like expiration.
|
|
228
|
+
*
|
|
229
|
+
* Checks the primary store for each key; if a key is missing and a secondary store is configured,
|
|
230
|
+
* it will fetch from the secondary store, repopulate the primary store, and return the results.
|
|
231
|
+
*
|
|
232
|
+
* @typeParam T - The expected type of the stored values.
|
|
233
|
+
* @param {string[]} keys - The cache keys to retrieve.
|
|
234
|
+
* @param {GetOptions} - options such as to bypass `nonBlocking` on this call
|
|
235
|
+
* @returns {Promise<Array<StoredDataRaw<T>>>}
|
|
236
|
+
* A promise that resolves to an array of raw data objects.
|
|
237
|
+
*/
|
|
238
|
+
getManyRaw<T>(keys: string[], options?: GetOptions): Promise<Array<StoredDataRaw<T>>>;
|
|
239
|
+
/**
|
|
240
|
+
* Retrieves multiple entries from the cache.
|
|
241
|
+
* Checks the primary store for each key; if a key is missing and a secondary store is configured,
|
|
242
|
+
* it will fetch from the secondary store, repopulate the primary store, and return the results.
|
|
243
|
+
*
|
|
244
|
+
* @typeParam T - The expected type of the stored values.
|
|
245
|
+
* @param {string[]} keys - The cache keys to retrieve.
|
|
246
|
+
* @param {GetOptions} - options such as to bypass `nonBlocking` on this call
|
|
247
|
+
* @returns {Promise<Array<T | undefined>>}
|
|
248
|
+
* A promise that resolves to an array of cached values or `undefined` for misses.
|
|
249
|
+
*/
|
|
250
|
+
getMany<T>(keys: string[], options?: GetOptions): Promise<Array<T | undefined>>;
|
|
666
251
|
/**
|
|
667
252
|
* Sets the value of the key. If the secondary store is set then it will also set the value in the secondary store.
|
|
668
253
|
* @param {string} key the key to set the value of
|
|
@@ -750,13 +335,45 @@ declare class Cacheable extends Hookified {
|
|
|
750
335
|
* @param {string} algorithm the hash algorithm to use. The default is 'sha256'
|
|
751
336
|
* @returns {string} the hash of the object
|
|
752
337
|
*/
|
|
753
|
-
hash(object: any, algorithm?:
|
|
754
|
-
private getSecondaryRawResults;
|
|
755
|
-
private getManySecondaryRawResults;
|
|
756
|
-
private deleteManyKeyv;
|
|
338
|
+
hash(object: any, algorithm?: HashAlgorithm): string;
|
|
757
339
|
private setManyKeyv;
|
|
758
340
|
private hasManyKeyv;
|
|
341
|
+
/**
|
|
342
|
+
* Processes a single key from secondary store for getRaw operation
|
|
343
|
+
* @param primary - the primary store to use
|
|
344
|
+
* @param secondary - the secondary store to use
|
|
345
|
+
* @param key - The key to retrieve from secondary store
|
|
346
|
+
* @returns Promise containing the result and TTL information
|
|
347
|
+
*/
|
|
348
|
+
private processSecondaryForGetRaw;
|
|
349
|
+
/**
|
|
350
|
+
* Processes a single key from secondary store for getRaw operation in non-blocking mode
|
|
351
|
+
* Non-blocking mode means we don't wait for secondary operations that update primary store
|
|
352
|
+
* @param primary - the primary store to use
|
|
353
|
+
* @param secondary - the secondary store to use
|
|
354
|
+
* @param key - The key to retrieve from secondary store
|
|
355
|
+
* @returns Promise containing the result and TTL information
|
|
356
|
+
*/
|
|
357
|
+
private processSecondaryForGetRawNonBlocking;
|
|
358
|
+
/**
|
|
359
|
+
* Processes missing keys from secondary store for getManyRaw operation
|
|
360
|
+
* @param primary - the primary store to use
|
|
361
|
+
* @param secondary - the secondary store to use
|
|
362
|
+
* @param keys - The original array of keys requested
|
|
363
|
+
* @param result - The result array from primary store (will be modified)
|
|
364
|
+
* @returns Promise<void>
|
|
365
|
+
*/
|
|
366
|
+
private processSecondaryForGetManyRaw;
|
|
367
|
+
/**
|
|
368
|
+
* Processes missing keys from secondary store for getManyRaw operation in non-blocking mode
|
|
369
|
+
* Non-blocking mode means we don't wait for secondary operations that update primary store
|
|
370
|
+
* @param secondary - the secondary store to use
|
|
371
|
+
* @param keys - The original array of keys requested
|
|
372
|
+
* @param result - The result array from primary store (will be modified)
|
|
373
|
+
* @returns Promise<void>
|
|
374
|
+
*/
|
|
375
|
+
private processSecondaryForGetManyRawNonBlocking;
|
|
759
376
|
private setTtl;
|
|
760
377
|
}
|
|
761
378
|
|
|
762
|
-
export { Cacheable, CacheableEvents, CacheableHooks, type
|
|
379
|
+
export { Cacheable, CacheableEvents, CacheableHooks, type CacheableOptions };
|