decache
decache (Delete Cache) lets you delete modules from node.js require() cache; useful when testing your modules/projects.
Last updated 2 months ago by nelsonic .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install decache 
SYNC missed versions from official npm registry.

decache

Delete a module from node.js' require.cache so you can freshly require it again.

Build Status codecov.io Code Climate maintainability Dependencies Status devDependencies Status contributions welcome HitCount

In node.js when you require() a module, node stores a cached version of the module, so that all subsequent calls to require() do not have to reload the module from the filesystem.

decache ( Delete Cache ) lets you delete modules from node.js require() cache this is useful when testing your modules/projects.

Why?

When testing our modules we often need to re-require the module being tested. This makes it easy.

What?

An easy way to delete a cached module.

How? (usage)

install

Install the module from npm:

npm install decache --save-dev

Use it in your code:

// require the decache module:
const decache = require('decache');

// require a module that you wrote"
let mymod = require('./mymodule.js');

// use your module the way you need to:
console.log(mymod.count()); // 0   (the initial state for our counter is zero)
console.log(mymod.incrementRunCount()); // 1

// delete the cached module:
decache('./mymodule.js');

//
mymod = require('./mymodule.js'); // fresh start
console.log(mymod.count()); // 0   (back to initial state ... zero)

Modules other than .js, like for example, .jsx, are supported as well.

Note that native modules with the .node extension are ignored from decaching because they behave unexpectedly when decached.

If you have any questions or need more examples, please create a GitHub issue: https://github.com/dwyl/decache/issues

Thanks!

Current Tags

  • 4.6.0                                ...           latest (2 months ago)

20 Versions

  • 4.6.0                                ...           2 months ago
  • 4.5.1                                ...           a year ago
  • 4.5.0                                ...           2 years ago
  • 4.4.1                                ...           2 years ago
  • 4.4.0                                ...           2 years ago
  • 4.3.0                                ...           3 years ago
  • 4.2.0                                ...           3 years ago
  • 4.1.0                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 3.1.0                                ...           4 years ago
  • 3.0.5                                ...           4 years ago
  • 3.0.4                                ...           4 years ago
  • 3.0.3                                ...           5 years ago
  • 3.0.2                                ...           5 years ago
  • 3.0.0                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 244
This Week 1,056
This Month 573
Last Day 329
Last Week 1,244
Last Month 6,742
Dependencies (1)
Dev Dependencies (6)
Dependents (185)

Copyright 2014 - 2016 © taobao.org |