medikoo / memoizee

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

Is there a way to geep cache alive until the provided function does not throw? #92

Closed aalexgabi closed 6 years ago

aalexgabi commented 6 years ago

For example I want to keep a cache that avoids executing a db query but I want that the cache is still available if db is down.

  1. Call memoized function that returns db a value
  2. Db goes down
  3. Cache expires
  4. Call memoized function that tries to query db which fails but still return the old value from the cache instead of failing

The idea is that sometimes is desirable to have an older value instead of failing.

medikoo commented 6 years ago

@aalexgabi it is planned to be provided with v1.

See description of invalidationSpan option at ttl section in https://github.com/medikoo/memoizee/issues/73

aalexgabi commented 6 years ago

@medikoo Thank you.