2014-01-16 48 views
2

我使用http.get()向節點發出請求,它一切正常,但在某些情況下,我得到一個過期版本的頁面(有一個日期字段,使我能夠確保)。該行爲確實是不一致的,我能得到正確的事情一個時刻,和錯誤的事情下...這裏是我的要求:node.js中的緩存控制http.get

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 
}); 

這有什麼錯的請求頭?我嘗試'max-age = 0'而不是'no-cache',無濟於事...,有沒有人有一個想法,這可能來自哪裏?在我的瀏覽器中,我始終得到最後一個版本,有點在這裏丟失,幫助!

+1

您是否嘗試過在最後附加一個隨機字符串?例如。 ''host.com'+(new Date()。valueOf())' – MMM

回答

2

解決它,這要歸功於用戶評論,我所做的是:

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 
}); 

愚蠢的,並在同一時間真棒......