export default function cacheFor < F extends Function > ( fn , ttl ) { let lastInvokedAt ; let lastReturnValue ; return function ( this ) { const now = Date . now ( ) ; if ( ! lastInvokedAt || now > lastInvokedAt + ttl ) { lastInvokedAt = now ; lastReturnValue = fn . apply ( this , arguments ) ; return lastReturnValue ; } return lastReturnValue ; } as any ; }