(appId, key, ttl, callback)
| 4 | } |
| 5 | |
| 6 | async get(appId, key, ttl, callback) { |
| 7 | key = `${appId}:${key}`; |
| 8 | const cached = this.cache[key]; |
| 9 | if (cached && cached.expiry > Date.now()) { |
| 10 | return cached.value; |
| 11 | } |
| 12 | |
| 13 | const value = await Promise.resolve(callback()); |
| 14 | this.cache[key] = { |
| 15 | value, |
| 16 | expiry: Date.now() + ttl, |
| 17 | }; |
| 18 | return value; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | module.exports = new KeyCache(); |
no test coverage detected