
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Delete module cache safely. This project is inspired by decache.
# use npm
npm install delcache
# or use yarn
yarn global add delcache
Node.js 10+
Deleting module cache is the precondition of 'hot reloading'. Typically, we delete the module cache by:
delete require.cache[require.resolve('xxx')]
However, this method can cause memory leakage. It clears the module cache in Module._cache
which is referenced by require.cache
, but it doesn't eliminate the reference in the array of xxx.parent.children
.
delcache
provides a way to eliminate both kinds of reference:
delcache('xxx')
In most cases, this is enough to clean up all references, with the following exception:
{
id: 'parentModule',
children: [{
id: 'childModuleA',
children: [{
id: 'targetModule'
}]
}, {
id: 'childModuleB',
children: [{
id: 'targetModule'
}]
}]
}
You will find targetModule
still in the children of childModuleA
after calling delcache(targetModule)
in childModuleB
. In this condition, you can pass true
as the second argument to delcache
: delcache(targetModule, true)
. delcache
will traverse the whole module tree to delete targetModule from children of every module.
When passing rootPath
as the third argument, delcache
will take it as the starting point. It is a recommended way to save time traversing the module tree.
Delete cache of target module and clear reference in parent's children:
const delcache = require('delcache')
let five = require('./five')
five.num = 6
delcache('./five')
five = require('./five')
console.log(five.num) // 5
Pass true
as the second argument to delete cache of target module from the whole module tree.
const delcache = require('delcache')
let five = require('./five')
five.num = 6
delcache('./five', true)
five = require('./five')
console.log(five.num) // 5
When the second argument is true
, you can specify the rootPath
from which clear the reference of the target module.
This is a recommended way to make the delete operation faster:
const delcache = require('delcache')
let five = require('./five')
five.num = 6
delcache('./five', true, '../../root')
five = require('./five')
console.log(five.num) // 5
Don't uese delete require.cache[xxx]
with delcache
, cause delcache
will check if a module is referenced by Module._cache
.
//parent.js
require('./a')
require('./b')
//a.js
require('./mod')
delete require.cache[require.resolve('./mod')]
//b.js
const delcache = require('delcahce')
delcache('./mod', true) // delcache can not eliminate the reference of mod in children of a.js
FAQs
delete module cache in node safely
We found that delcache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.