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

[KeyvAdapter] Allow return "undefined" when cache backend is unavailable #211

Closed
PhantomRay opened this issue Oct 25, 2022 · 1 comment
Closed

Comments

@PhantomRay
Copy link

I am using @apollo/utils.keyvadapter to implement redis cache backend. The adapter makes redis or other cache backend a hard dependency. This means when the apollo server lost connection to redis server, any incoming requests will fail. It would be good to allow the redis client to retry connection. At the same time, any queries with cache control should still function by bypassing cache.

Meanwhile, I use the following code to achieve the goal.

class BetterKeyvAdapter extends KeyvAdapter {
  // this will allow the query to bypass the cache if cache backend is not available
  async get(key) {
    try {
      return await super.get(key);
    } catch (e) {
      return undefined;
    }
  }
}
@glasser
Copy link
Member

glasser commented Oct 25, 2022

It looks like you're looking for ErrorsAreMissesCache, a KeyValueCache implementation that wraps another KeyValueCache implementation. It is provided by @apollo/utils.keyvaluecache.

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

2 participants