(key)
| 20 | } |
| 21 | |
| 22 | get(key) { |
| 23 | let v = this.cache.get(key); |
| 24 | if (v !== undefined) { |
| 25 | // Remove the found element from the cache so it can be inserted it again |
| 26 | // at the end before returning. |
| 27 | this.cache.delete(key); |
| 28 | } else { |
| 29 | v = this.getFunc(key); |
| 30 | if (this.cache.size > this.cache.maxSize) { |
| 31 | // Evict the oldest item from the cache. |
| 32 | this.cache.delete(this.cache.keys().next().value); |
| 33 | } |
| 34 | } |
| 35 | this.cache.set(key, v); |
| 36 | return v; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /*** Colors for Offsets **********************************************************/ |
no test coverage detected