export function createMemoryCache < T , Args extends any [ ] > ( getter , argsSerializer ) { const cacheMap = new Map < string , T > ( ) ; return function getWithCache ( ... args ) { const serializedArgs = argsSerializer ( ... args ) ; const cachedValue = cacheMap . get ( serializedArgs ) ; if ( cachedValue ) { return cachedValue ; } const newValue = getter ( ... args ) ; cacheMap . set ( serializedArgs , newValue ) ; return newValue ; } ; }