node-cache-helper
Advanced tools
+1
-1
@@ -9,3 +9,3 @@ import * as NodeCache from "node-cache"; | ||
| constructor(config?: Options); | ||
| register(prefix: string, reloadFn: Function); | ||
| register(prefix: string, reloadFn: Function, ttl?: number | string); | ||
| resetKey(key: string): Promise<any>; | ||
@@ -12,0 +12,0 @@ get(key: string): Promise<any>; |
+4
-5
@@ -16,6 +16,7 @@ const NodeCache = require('node-cache') | ||
| register(prefix, reloadFn) { | ||
| register(prefix, reloadFn, ttl) { | ||
| this.registerMap[prefix] = { | ||
| prefix, | ||
| reloadFn, | ||
| ttl, | ||
| } | ||
@@ -27,4 +28,3 @@ } | ||
| let prefix = spl[0] | ||
| let reloadFn = this.registerMap[prefix]?.reloadFn | ||
| let { reloadFn, ttl } = this.registerMap[prefix] ?? {} | ||
| if (reloadFn == null) { | ||
@@ -35,3 +35,3 @@ return null | ||
| let newValue = await reloadFn(...spl) | ||
| this.instance.set(key, newValue) | ||
| this.instance.set(key, newValue, ttl) | ||
| return newValue | ||
@@ -50,3 +50,2 @@ } | ||
| this.instance.on('expired', key => { | ||
| console.log('expired', key) | ||
| this.resetKey(key).then().catch(console.error) | ||
@@ -53,0 +52,0 @@ }) |
+1
-1
| { | ||
| "name": "node-cache-helper", | ||
| "version": "0.0.3", | ||
| "version": "0.0.4", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/cache.js", |
5345
0.26%