(key, value, ttl = this.ttl)
| 23 | } |
| 24 | |
| 25 | put(key, value, ttl = this.ttl) { |
| 26 | if (ttl < 0 || isNaN(ttl)) { |
| 27 | ttl = NaN; |
| 28 | } |
| 29 | |
| 30 | var record = { |
| 31 | value: value, |
| 32 | expire: ttl + Date.now(), |
| 33 | }; |
| 34 | |
| 35 | if (!isNaN(record.expire)) { |
| 36 | record.timeout = setTimeout(() => { |
| 37 | this.del(key); |
| 38 | }, ttl); |
| 39 | } |
| 40 | |
| 41 | this.cache[key] = record; |
| 42 | } |
| 43 | |
| 44 | del(key) { |
| 45 | var record = this.cache[key]; |