medikoo / memoizee

Complete memoize/cache solution for JavaScript
ISC License
1.74k stars 61 forks source link

Graceful handling of un-refreshable #10

Closed rektide closed 10 years ago

rektide commented 10 years ago

Hello,

I'd love a way to be able to have my method throw a special exception (or return a special value) that indicates that a refresh at this time is not possible, causing the old expired data to continue to be used.

Ideally the exception could also specify some kind of retry policy: wait 20% more expiry before trying again.

Memoize wraps an HTTP client in my case, and I'd like to build in a way of dealing with the target service being absent.

medikoo commented 10 years ago

Hey @rektide

I think it's more high-level use case, and it should be addressed outside of memoizee, otherwise it will need introduction of some high complexity into core, just for this rare case. I think it's bad idea to proceed with that

Best way probably is to provide some handler in a middle as memoize(customHander(fnToMemoize)) which will provide logic you're after e.g. return previous value on crash, and you can assure more custom maxAge logic and not use one bundled with memoizee, so e.g.

I will close it for now, but if I didn't get something right, or you'd like to clarify further, let's continue discussion here