jxmot / router-log-monitor

A utility that monitors Netgear R6400 logs received via email(IMAP). It processes them and parses each entry for writing into a database.
MIT License
0 stars 0 forks source link

`require()` Caching - causes issues with reports #17

Closed jxmot closed 3 years ago

jxmot commented 3 years ago

The fact that require() will cache modules, and will not reload them even with explicit require() calls.

A work-around or means to disable the caching is needed.

jxmot commented 3 years ago

This is the work-around (tested OK) -

    // NOTE: require() does caching of modules, info:
    //      https://bambielli.com/til/2017-04-30-node-require-cache/
    //
    // Also using every() instead of forEach() to allow the ability
    // to break the loop:
    //      https://masteringjs.io/tutorials/fundamentals/foreach-break
    Object.keys(require.cache).every( (key) => {
        if(key.includes('reportdefs.js')) {
            // remove the module from the cache
            delete require.cache[key];
            // done!
            return false;
        }
        return true;
    });

    const reportdefs = require('./reportdefs.js');
jxmot commented 3 years ago

resolved in the 20210531-logreporter branch