我已经读过为了避免在nodejs中缓存,有必要使用:
"res.header('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');"
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何使用它,因为当我在代码中放入该行时会出现错误.
我的功能(我认为我必须编程没有缓存)是:
function getFile(localPath, mimeType, res) {
fs.readFile(localPath, function(err, contents) {
if (!err) {
res.writeHead(200, {
"Content-Type": mimeType,
"Content-Length": contents.length,
'Accept-Ranges': 'bytes',
});
//res.header('Cache-Control', 'no-cache');
res.end(contents);
} else {
res.writeHead(500);
res.end();
}
});
}
Run Code Online (Sandbox Code Playgroud)
有谁知道如何在我的代码中没有缓存?谢谢