(key, value)
| 23 | } |
| 24 | |
| 25 | set (key, value) { |
| 26 | const deleted = this.delete(key) |
| 27 | |
| 28 | if (!deleted && value !== undefined) { |
| 29 | // If cache is full, delete the least recently used item |
| 30 | if (this.map.size >= this.max) { |
| 31 | const firstKey = this.map.keys().next().value |
| 32 | this.delete(firstKey) |
| 33 | } |
| 34 | |
| 35 | this.map.set(key, value) |
| 36 | } |
| 37 | |
| 38 | return this |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | module.exports = LRUCache |
no test coverage detected