(...key: TKey)
| 5 | const cache = new Map<CacheKeyFragment, any>(); |
| 6 | |
| 7 | function get(...key: TKey): TEntry { |
| 8 | const lastKey = key.slice(-1)[0]; |
| 9 | |
| 10 | const nestedCache = getCache(cache, ...key); |
| 11 | |
| 12 | return nestedCache.has(lastKey) |
| 13 | ? nestedCache.get(lastKey) |
| 14 | : nestedCache.set(lastKey, fn(...key)).get(lastKey); |
| 15 | } |
| 16 | |
| 17 | return {get}; |
| 18 | }; |