@@ -86,8 +86,8 @@ The `NodeCacheStore` is a class that extends the `NodeCache` and adds the abilit
8686import {NodeCacheStore } from ' @cacheable/node-cache' ;
8787
8888const cache = new NodeCacheStore ();
89- cache .set (' foo' , ' bar' );
90- cache .get (' foo' ); // 'bar'
89+ await cache .set (' foo' , ' bar' );
90+ await cache .get (' foo' ); // 'bar'
9191```
9292
9393## NodeCacheStoreOptions
@@ -108,8 +108,8 @@ Note: the `ttl` is now in milliseconds and not seconds like `stdTTL` in `NodeCac
108108
109109``` javascript
110110const cache = new NodeCacheStore ({ttl: 60000 }); // 1 minute as it defaults to milliseconds
111- cache .set (' foo' , ' bar' , ' 1h' ); // 1 hour
112- cache .set (' longfoo' , ' bar' , ' 1d' ); // 1 day
111+ await cache .set (' foo' , ' bar' , ' 1h' ); // 1 hour
112+ await cache .set (' longfoo' , ' bar' , ' 1d' ); // 1 day
113113```
114114
115115## Node Cache Store API
@@ -161,20 +161,20 @@ cache.on('expired', (key, value) => {
161161});
162162```
163163
164- ## ` .set(key: string | number, value: any, ttl?: number): boolean `
164+ ## ` .set(key: string | number, value: any, ttl?: number): Promise< boolean> `
165165
166166Set a key value pair with an optional ttl (in seconds). Will return true on success. If the ttl is not set it will default to 0 (no ttl).
167167
168168``` javascript
169- cache .set (' foo' , ' bar' , 10 ); // true
169+ await cache .set (' foo' , ' bar' , 10 ); // true
170170```
171171
172- ## ` .mset(data: Array<NodeCacheItem>): boolean `
172+ ## ` .mset(data: Array<NodeCacheItem>): Promise< boolean> `
173173
174174Set multiple key value pairs at once. This will take an array of objects with the key, value, and optional ttl.
175175
176176``` javascript
177- cache .mset ([{key: ' foo' , value: ' bar' , ttl: 10 }, {key: ' bar' , value: ' baz' }]); // true
177+ await cache .mset ([{key: ' foo' , value: ' bar' , ttl: 10 }, {key: ' bar' , value: ' baz' }]); // true
178178```
179179
180180the ` NodeCacheItem ` is defined as:
@@ -187,89 +187,89 @@ export type NodeCacheItem = {
187187};
188188```
189189
190- ## ` .get(key: string | number): any `
190+ ## ` .get(key: string | number): Promise< any> `
191191
192192Get a value from the cache by key. If the key does not exist it will return ` undefined ` .
193193
194194``` javascript
195195cache .get (' foo' ); // 'bar'
196196```
197197
198- ## ` mget(keys: Array<string | number>): Record<string, unknown> `
198+ ## ` mget(keys: Array<string | number>): Promise< Record<string, unknown> > `
199199
200200Get multiple values from the cache by keys. This will return an object with the keys and values.
201201
202202``` javascript
203203const obj = { my: ' value' , my2: ' value2' };
204204const obj2 = { special: ' value3' , life: ' value4' };
205- cache .set (' my' , obj);
206- cache .set (' my2' , obj2);
207- cache .mget ([' my' , ' my2' ]); // { my: { my: 'value', my2: 'value2' }, my2: { special: 'value3', life: 'value4' } }
205+ await cache .set (' my' , obj);
206+ await cache .set (' my2' , obj2);
207+ await cache .mget ([' my' , ' my2' ]); // { my: { my: 'value', my2: 'value2' }, my2: { special: 'value3', life: 'value4' } }
208208```
209209
210- ## ` take(key: string | number): any `
210+ ## ` take(key: string | number): Promise<T> `
211211
212212Get a value from the cache by key and delete it. If the key does not exist it will return ` undefined ` .
213213
214214``` javascript
215- cache .set (' foo' , ' bar' );
216- cache .take (' foo' ); // 'bar'
217- cache .get (' foo' ); // undefined
215+ await cache .set (' foo' , ' bar' );
216+ await cache .take (' foo' ); // 'bar'
217+ await cache .get (' foo' ); // undefined
218218```
219219
220- ## ` del(key: string | number | Array<string | number>): number `
220+ ## ` del(key: string | number | Array<string | number>): Promise< number> `
221221
222222Delete a key from the cache. Will return the number of deleted entries and never fail. You can also pass in an array of keys to delete multiple keys. All examples assume that you have initialized the cache like ` const cache = new NodeCache(); ` .
223223
224224``` javascript
225- cache .del (' foo' ); // true
225+ await cache .del (' foo' ); // true
226226```
227227
228228passing in an array of keys:
229229
230230``` javascript
231- cache .del ([' foo' , ' bar' ]); // true
231+ await cache .del ([' foo' , ' bar' ]); // true
232232```
233233
234- ## ` .mdel(keys: Array<string | number>): number `
234+ ## ` .mdel(keys: Array<string | number>): Promise< number> `
235235
236236Delete multiple keys from the cache. Will return the number of deleted entries and never fail.
237237
238238``` javascript
239- cache .mdel ([' foo' , ' bar' ]); // true
239+ await cache .mdel ([' foo' , ' bar' ]); // true
240240```
241241
242- ## ` .ttl(key: string | number, ttl?: number): boolean `
242+ ## ` .ttl(key: string | number, ttl?: number): Promise< boolean> `
243243
244244Redefine the ttl of a key. Returns true if the key has been found and changed. Otherwise returns false. If the ttl-argument isn't passed the default-TTL will be used.
245245
246246``` javascript
247- cache .ttl (' foo' , 10 ); // true
247+ await cache .ttl (' foo' , 10 ); // true
248248```
249249
250- ## ` getTtl(key: string | number): number | undefined `
250+ ## ` getTtl(key: string | number): Promise< number | undefined> `
251251
252252Get the ttl expiration from ` Date.now() ` of a key. If the key does not exist it will return ` undefined ` .
253253
254254``` javascript
255- cache .getTtl (' foo' ); // 1725993344859
255+ await cache .getTtl (' foo' ); // 1725993344859
256256```
257257
258- ## ` has(key: string | number): boolean `
258+ ## ` has(key: string | number): Promise< boolean> `
259259
260260Check if a key exists in the cache.
261261
262262``` javascript
263- cache .set (' foo' , ' bar' );
264- cache .has (' foo' ); // true
263+ await cache .set (' foo' , ' bar' );
264+ await cache .has (' foo' ); // true
265265```
266266
267- ## ` keys(): Array<string> `
267+ ## ` keys(): Promise< Array<string> > `
268268
269269Get all keys from the cache.
270270
271271``` javascript
272- cache .keys (); // ['foo', 'bar']
272+ await cache .keys (); // ['foo', 'bar']
273273```
274274
275275## ` getStats(): NodeCacheStats `
@@ -286,7 +286,7 @@ Flush the cache. Will remove all keys and reset the stats.
286286
287287``` javascript
288288cache .flushAll ();
289- cache .keys (); // []
289+ await cache .keys (); // []
290290cache .getStats (); // {hits: 0, misses: 0, keys: 0, ksize: 0, vsize: 0}
291291```
292292
@@ -295,18 +295,10 @@ cache.getStats(); // {hits: 0, misses: 0, keys: 0, ksize: 0, vsize: 0}
295295Flush the stats. Will reset the stats but keep the keys.
296296
297297``` javascript
298- cache .set (' foo' , ' bar' );
298+ await cache .set (' foo' , ' bar' );
299299cache .flushStats ();
300300cache .getStats (); // {hits: 0, misses: 0, keys: 0, ksize: 0, vsize: 0}
301- cache .keys (); // ['foo']
302- ```
303-
304- ## ` close(): void `
305-
306- this will stop the interval that is running for the ` checkperiod ` and ` deleteOnExpire ` options.
307-
308- ``` javascript
309- cache .close ();
301+ await cache .keys (); // ['foo']
310302```
311303
312304## ` on(event: string, callback: Function): void `
0 commit comments