简体   繁体   中英

Cache-Control in node.js http.get

I'm making requests to JSON objects with node using http.get(), it all works fine but, in some cases, I get an outdated version of the page (there's a date field that enables me to make sure). The behaviour is really inconsistent, I can get the right thing one moment, and the wrong thing the next... Here's my request :

var options = {host:'host.com',path:urlPath,headers:{'Cache-Control':'no-cache'}}
http.get(options, function(res){
    //JSON.parse result and check the date, sometimes 17/1, sometimes 10/1
});

Is there anything wrong with the request header? I tried 'max-age=0' instead of 'no-cache', to no avail..., does anyone have an idea where this could come from? In my browser, I get the last version all the time, a bit lost here, Help!

Solved it, thanks to users comment, what I did is :

urlPath+="&ie="+(new Date()).getTime();
var options = {host:'host.com',path:urlPath,headers:{'Cache-Control':'no-cache'}}
http.get(options, function(res){
    //JSON.parse result and check the date, sometimes 17/1, sometimes 10/1
});

Stupid and awesome at the same time...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM