Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, you can access the cache via <code>require.cache[moduleName]</code> where <code>moduleName</code> is the name of the module you wish to access. Deleting an entry by calling <code>delete require.cache[moduleName]</code> will cause <code>require</code> to load the actual file.</p> <p>This is how you would remove all cached files associated with the module:</p> <pre><code>/** * Removes a module from the cache */ function purgeCache(moduleName) { // Traverse the cache looking for the files // loaded by the specified module name searchCache(moduleName, function (mod) { delete require.cache[mod.id]; }); // Remove cached paths to the module. // Thanks to @bentael for pointing this out. Object.keys(module.constructor._pathCache).forEach(function(cacheKey) { if (cacheKey.indexOf(moduleName)&gt;0) { delete module.constructor._pathCache[cacheKey]; } }); }; /** * Traverses the cache to search for all the cached * files of the specified module name */ function searchCache(moduleName, callback) { // Resolve the module identified by the specified name var mod = require.resolve(moduleName); // Check if the module has been resolved and found within // the cache if (mod &amp;&amp; ((mod = require.cache[mod]) !== undefined)) { // Recursively go over the results (function traverse(mod) { // Go over each of the module's children and // traverse them mod.children.forEach(function (child) { traverse(child); }); // Call the specified callback providing the // found cached module callback(mod); }(mod)); } }; </code></pre> <p>Usage would be:</p> <pre><code>// Load the package var mypackage = require('./mypackage'); // Purge the package from cache purgeCache('./mypackage'); </code></pre> <p>Since this code uses the same resolver <code>require</code> does, just specify whatever you would for require.</p> <hr> <blockquote> <p>"Unix was not designed to stop its users from doing stupid things, as that would also stop them from doing clever things." – Doug Gwyn</p> </blockquote> <p>I think that there <em>should</em> have been a way for performing an explicit uncached module loading.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload