sindresorhus / p-memoize

Memoize promise-returning & async functions
MIT License
397 stars 30 forks source link

Miss-leading usage example #40

Closed zanonnicola closed 2 years ago

zanonnicola commented 2 years ago

In the README file the first example implies that the last call won't be memoized since the cache is expired (https://github.com/sindresorhus/p-memoize/blob/main/readme.md?plain=1#L35)

const memoizedGot = pMemoize(got);

await memoizedGot('https://sindresorhus.com');

// This call is cached
await memoizedGot('https://sindresorhus.com');

await delay(2000);

// This call is not cached as the cache has expired
await memoizedGot('https://sindresorhus.com');

I think this is miss-leading (as far as I understood it) since the default cache that is used here it's not time-based (or at least should never expire with Number.POSITIVE_INFINITY). It requires to pass a different Map as described here.

Am I miss something here?

fregante commented 2 years ago

Indeed this is because parts of the readme have been copied from mem, which does have a time-base expiration:

https://github.com/sindresorhus/mem#maxage