sindresorhus / p-memoize

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

Feature request: Return stale value while revalidating #19

Closed futpib closed 3 years ago

futpib commented 3 years ago

When used with maxAge option, when the cache entry has expired, memoized function could return last cached value while waiting for a new result to arrive.

papb commented 3 years ago

I think this could be an option, but not on by default.

sindresorhus commented 3 years ago

Yeah, sounds useful as an opt-in option.

AmrSaber commented 3 years ago

Hello @sindresorhus, I am interested in helping out with this feature. How can I help with it?

Richienb commented 3 years ago

@AmrSaber PRs are always welcome

AmrSaber commented 3 years ago

I don't understand how #26 closes this ticket? How do we achieve the stale-while-revalidate scenario now?

Richienb commented 3 years ago

26 Moves this feature into userland.

AmrSaber commented 3 years ago

Can you show an example of how to achieve this?

Richienb commented 3 years ago

False alarm: after the previous PR, I'm not sure how to check if a value is stale anymore to then call the function again.

futpib commented 3 years ago

Should this be reopened then?

Richienb commented 3 years ago

Yes, but with the new goal of adding an API to the cache storage object to check whether the object is stale and whether stale-while-revalidate should be used