2016-03-23 18 views
2

我在github上放了一些數據。
我使用節點模塊「請求」從中獲取數據。
我在github上更新我的數據後。
nodejs仍舊獲得約五分鐘的舊數據。
這是我的代碼的一部分。
我已經更新了github上的數據,但節點模塊請求仍然得到舊數據

var url = "https://raw.githubusercontent.com/Larry850806/facebook-chat-bot/master/db.json"; 
request({ url: url, json: true }, function(error, response, body){ 
    if (!error && response.statusCode === 200) { 
     console.log(body); // Print the json response 
     // after I update data, body still get old data 
    } 
}); 

我認爲這是因爲有一個緩存。
所以我不能得到「真實」的數據,但老的數據。
有什麼辦法獲得最新的數據?

回答

2

的確有一個Github緩存。你可能想要嘗試的一件事是在你要求的文件末尾附加一個隨機查詢字符串。

例如:

var url = "https://raw.githubusercontent.com/Larry850806/facebook-chat-bot/master/db.json?random=<randomnumberhere>"; 
request({ url: url, json: true }, function(error, response, body){ 
    if (!error && response.statusCode === 200) { 
     console.log(body); // Print the json response 
     // after I update data, body still get old data 
    } 
}); 

有時這「力量」的後端服務器打破緩存(如果他們正在尋找的查詢字符串)。

+0

謝謝,它的工作原理。 –

相關問題