-
Notifications
You must be signed in to change notification settings - Fork 93
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
How to add caching capabilities #295
Comments
I managed to do something similar using
The main issue you need we encountered was compression handling; you would need to decompress and recompress the response body during |
I don't think that approach improves the overall latency. You would need to skip calling the handler to have any caching benefit, e.g. sending a response in the preHandler hook. |
I understand that, so need to call reply.send in prehandler. However my problem is how to cache the origin result since the fastify-reply returns a read stream from the origin. |
You would need to accumulate the stream in the onSend hook and then send it back. Take also a look at the cloneable-readable module to "fork" the stream so you can still stream back the response while you accumulate. |
Note that I recommend to not use this module for that use case. GraphQL does not really follow REST semantics so it's better to cache manually or have a graphqql aware cache. |
Prerequisites
Fastify version
4.5.3
Plugin version
^9.0.0
Node.js version
18
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
macosx
Description
First thanks for this library,
I am trying to create a graphql proxy with caching capabilities. Therefor I am trying to use
fastify.addHook('preHandler', ...)
to parse the query and possibly retrieve result from cache andfastify.addHook('onSend', ...)
to store the cache however I am kind of stuck on storing the cache value from onSend hook. In general, how can cache be implemented inside proxy usingfastify-http-proxy
?Steps to Reproduce
Expected Behavior
The text was updated successfully, but these errors were encountered: