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

[plugin-response-cache] Allow return "null" when cache backend is unavailable #7075

Closed
PhantomRay opened this issue Oct 25, 2022 · 5 comments

Comments

@PhantomRay
Copy link
Contributor

PhantomRay commented Oct 25, 2022

I am using plugin-response-cache to implement redis cache backend. The plugin 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.

This can be achieved easily by adding try-catch block to this line.

let serializedValue = undefined;
try {
  serializedValue = await cache.get(key);
  if (serializedValue === undefined) {
    return null;
  }
} catch (err) {
  return null;
}

Is it worth to add this feature? Meanwhile, if apollo server losts redis connection, the service is totally unusable.

@PhantomRay
Copy link
Contributor Author

It could be addressed in @apollo/utils.keyvadapter.

I created an issue there. apollographql/apollo-utils#211

@glasser
Copy link
Member

glasser commented Oct 25, 2022

Thanks, I mentioned on that issue that you can opt in to this functionality via ErrorsAreMissesCache. apollographql/apollo-utils#211 (comment)

@glasser glasser closed this as completed Oct 25, 2022
@PhantomRay
Copy link
Contributor Author

PhantomRay commented Oct 26, 2022

Hi @glasser, thanks for the useful info. I implemented the feature according to official docs https://www.apollographql.com/docs/apollo-server/performance/cache-backends/

It would be great if this is mentioned there.

@glasser
Copy link
Member

glasser commented Oct 26, 2022

@PhantomRay
Copy link
Contributor Author

@glasser I will add it soon.

rkoron007 added a commit that referenced this issue Nov 2, 2022
This is a request from @glasser in relates to this issue
#7075

Co-authored-by: Rose M Koron <32436232+rkoron007@users.noreply.github.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants