-
Notifications
You must be signed in to change notification settings - Fork 2k
Add support for caching #219
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
Comments
I think that this functionality would be best suited in another library that uses |
This should be easy to do as a middleware or using a connect middleware like https://github.com/tdebarochez/connect-cache ? |
Awesome suggestion @vvo Thanks! i will try this tomorrow. |
i have given up on this,
The request gets cached and everything works fine but once i do ctrl f5 a few time the connect-cache blows out. i have to say its a sad cache. |
ctrl+f5 will send out 'cache-control:no-cache' headers which means 'refresh the cache' so there's must be something in the connect cache code to handle this. Im sure it will work, debug, read the connect cache code. good luck |
@kul how did you get this to work? I can see how using the |
oh i am sorry i deleted the fork by mistake but the original repo had merged the pull request tdebarochez/connect-cache@05bfdc6. |
I get that it is a cache miss; what I didn't get is how you got the data in the cache in the first place. Once you have a cache miss, and you pass it on to http-proxy, how did you intercept the response to add it to the cache? |
I am sorry if i am missing something here, did you try reading the node http proxy's and connect-cache's home page ? I may be a little rusty here, long time since i used node-http-proxy. Apologies. 👾 |
@deitch Did you happen to work out how to intercept a response? |
Yeah, I used req.use(myMiddleware); where myMiddleware is like: httpProxy = require('http-proxy'), proxy = new httpProxy.HttpProxy(config);
module.exports = function(req,res,next) {
if (isInCache) {
// send response from cache
} else {
wrapResponse(res);
proxy.proxyRequest(req,res,httpProxy.buffer(req));
}
}
Conceptually simple, in practice was a beast, but works nicely. |
Thanks, @deitch. |
Support for caching would be an awesome addition. Something along the lines of nginx
location ~* .(jpg|png|gif|jpeg|css|js|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx)$ {
proxy_buffering on;
proxy_cache_valid 200 120m;
expires 864000;
}
The text was updated successfully, but these errors were encountered: