簡體   English   中英

node.js http.get中的緩存控制

[英]Cache-Control in node.js http.get

我正在使用http.get()向帶有節點的JSON對象發出請求,這一切都很好,但是在某些情況下,我得到了該頁面的過時版本(有一個日期字段使我可以確定)。 行為確實前后矛盾,我一會兒就能得到正確的東西,下一分鍾我就可以得到錯誤的東西……這是我的要求:

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”,但無濟於事...,有人知道這可能來自哪里嗎? 在我的瀏覽器中,我一直都在獲取最新版本,在這里有些迷失了,幫助!

解決了,感謝用戶的評論,我所做的是:

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

愚蠢而又棒極了...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM