nodejs服务器中没有缓存

 沥胆披肝365_781 发布于 2023-02-12 13:32

我已经读过为了避免在nodejs中缓存,有必要使用:

"res.header('Cache-Control', 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');"

但是我不知道如何使用它,因为当我在代码中放入该行时会出现错误.

我的功能(我认为我必须编程没有缓存)是:

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

}

有谁知道如何在我的代码中没有缓存?谢谢

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有