require.cache
添加於:v0.3.0
需要時,模塊會緩存在此對象中。通過從此對象中刪除鍵值,下一個require
將重新加載模塊。這不適用於 native addons ,重新加載將導致錯誤。
添加或替換條目也是可能的。此緩存在本機模塊之前檢查,如果將與本機模塊匹配的名稱添加到緩存中,則隻有 node:
-prefixed require 調用將接收本機模塊。小心使用!
const assert = require('node:assert');
const realFs = require('node:fs');
const fakeFs = {};
require.cache.fs = { exports: fakeFs };
assert.strictEqual(require('node:fs'), fakeFs);
assert.strictEqual(require('node:fs'), realFs);
相關用法
- Node.js require.main用法及代碼示例
- Node.js require.extensions用法及代碼示例
- Node.js require(id)用法及代碼示例
- Node.js http2.Http2ServerRequest request.url用法及代碼示例
- Node.js request.socket用法及代碼示例
- Node.js http.ClientRequest request.getHeaders()用法及代碼示例
- Node.js http2.Http2ServerRequest request.headers用法及代碼示例
- Node.js http.ClientRequest request.setHeader(name, value)用法及代碼示例
- Node.js request.writableEnded用法及代碼示例
- Node.js http.ClientRequest request.getHeaderNames()用法及代碼示例
- Node.js http.ClientRequest request.removeHeader(name)用法及代碼示例
- Node.js http.ClientRequest request.getHeader(name)用法及代碼示例
- Node.js http.ClientRequest request.reusedSocket用法及代碼示例
- Node.js http2.Http2ServerRequest request.rawHeaders用法及代碼示例
- Node.js http.ClientRequest request.hasHeader(name)用法及代碼示例
- Node.js http.ClientRequest request.getRawHeaderNames()用法及代碼示例
- Node.js http.ClientRequest request.socket用法及代碼示例
- Node.js http.ServerResponse response.statusCode用法及代碼示例
- Node.js readStream.isRaw用法及代碼示例
- Node.js response.writeContinue()用法及代碼示例
- Node.js http2.Http2ServerResponse response.removeHeader(name)用法及代碼示例
- Node.js response.removeHeader()用法及代碼示例
- Node.js http.ServerResponse response.getHeaderNames()用法及代碼示例
- Node.js http2.Http2ServerResponse response.hasHeader(name)用法及代碼示例
- Node.js http.ServerResponse response.removeHeader(name)用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 require.cache。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。