Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning expired cache as a fallback #66

Open
terrabythia opened this issue Oct 13, 2022 · 0 comments
Open

Returning expired cache as a fallback #66

terrabythia opened this issue Oct 13, 2022 · 0 comments

Comments

@terrabythia
Copy link

Not entirely sure if this isn't already possible, but I couldn't find out how to.

When I use a callback in the getOrElse() function to retrieve new data (and save it), I would like to be able to return the old/expired cache data (if any) whenever there was a problem fetching new data as a fallback. Something like this would be great:

cache.getOrElse(cacheKey, async (oldCache) => {
  try {
    return await fetchNewData();
  }
  catch(error) {
    // return old cache if new data fetch fails
    return oldCache;
  }
});

Is this possible in some other way I'm not aware of?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant