node.js require() cache - possible to invalidate?

后端 未结 17 1657
我寻月下人不归
我寻月下人不归 2020-11-22 06:52

From the node.js documentation:

Modules are cached after the first time they are loaded. This means (among other things) that every call to require(\'

17条回答
  •  忘了有多久
    2020-11-22 07:27

    Yes, you can invalidate cache.

    The cache is stored in an object called require.cache which you can access directly according to filenames (e.g. - /projects/app/home/index.js as opposed to ./home which you would use in a require('./home') statement).

    delete require.cache['/projects/app/home/index.js'];
    

    Our team has found the following module useful. To invalidate certain groups of modules.

    https://www.npmjs.com/package/node-resource

提交回复
热议问题