File size: 330 Bytes
a01b242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 };