Spaces:
Paused
Paused
| const cache = {}; | |
| function set(key, value, ttl = 5000) { | |
| cache[key] = { | |
| value, | |
| expiry: Date.now() + ttl | |
| }; | |
| } | |
| function get(key) { | |
| const item = cache[key]; | |
| if (!item) return null; | |
| if (Date.now() > item.expiry) { | |
| delete cache[key]; | |
| return null; | |
| } | |
| return item.value; | |
| } | |
| module.exports = { set, get }; |