node.js 的 readFileSync 是否缓存读取的文件?

Does readFileSync of node.js cache the read files?

fs.readFileSync 个 node.js 个缓存已读取的文件?

我不认为是这样,因为文档没有这么说,但我的代码是这样的..

代码相关部分

     // after mainPath file is altered, it's not reflected until I restart node.js
     var scriptString =  fs.readFileSync(mainPath);
     var app = vm.createScript(scriptString, mainPath); 

     // Run the app

     app.runInContext(context);

读取在给定的读取操作期间被缓冲。例如。当你要求读取一个字节时,它可能会读取比单个字节更多的字节到缓冲区中,然后 return 那个单个字节给你。但除此之外,node.js 中没有内置从一次读取文件到另一次读取的缓存。而且,如果您使用 readFileSync() 一次读取整个文件,则此缓冲不会影响您。

OS 本身会在 node.js 下进行缓存,但这通常是直写缓存,旨在保存磁盘读取,但永远不会有陈旧数据。