1 | # decache
|
2 |
|
3 | [![Build Status](https://travis-ci.org/dwyl/decache.svg)](https://travis-ci.org/dwyl/decache)
|
4 | [![codecov.io](https://codecov.io/github/dwyl/decache/coverage.svg?branch=master)](https://codecov.io/github/dwyl/decache?branch=master)
|
5 | [![Code Climate](https://codeclimate.com/github/dwyl/decache/badges/gpa.svg)](https://codeclimate.com/github/dwyl/decache)
|
6 | [![Dependency Status](https://david-dm.org/dwyl/decache.svg)](https://david-dm.org/dwyl/decache)
|
7 | [![devDependency Status](https://david-dm.org/dwyl/decache/dev-status.svg)](https://david-dm.org/dwyl/decache#info=devDependencies)
|
8 |
|
9 | In node.js when you `require()` a module, node stores a cached version of the
|
10 | module, so that all subsequent calls to `require()` do not have to reload
|
11 | the module from the filesystem.
|
12 |
|
13 | `decache` ( _**De**lete **Cache**_ ) lets you delete modules from node.js `require()` cache
|
14 | this is useful when _**testing**_ your modules/projects.
|
15 |
|
16 | ## Why?
|
17 |
|
18 | When testing our modules we often need to re-require the module being tested.
|
19 | This makes it easy.
|
20 |
|
21 | ## What?
|
22 |
|
23 | An easy way to delete a cached module.
|
24 |
|
25 | ## How? (_usage_)
|
26 |
|
27 | ### install
|
28 |
|
29 | Install the module from npm:
|
30 |
|
31 | ```sh
|
32 | npm install decache --save-dev
|
33 | ```
|
34 |
|
35 | ### Use it in your code:
|
36 |
|
37 | ```js
|
38 | // require the decache module:
|
39 | var decache = require('decache');
|
40 |
|
41 | // require a module that you wrote"
|
42 | var mymod = require('./mymodule.js');
|
43 |
|
44 | // use your module the way you need to:
|
45 | console.log(mymod.count()); // 0 (the initial state for our counter is zero)
|
46 | console.log(mymod.incrementRunCount()); // 1
|
47 |
|
48 | // delete the cached module:
|
49 | decache('./mymodule.js');
|
50 |
|
51 | //
|
52 | mymod = require('./mymodule.js'); // fresh start
|
53 | console.log(mymod.count()); // 0 (back to initial state ... zero)
|
54 | ```
|
55 |
|
56 | Modules other than `.js`, like for example, `.jsx`, are supported as well.
|
57 |
|
58 | If you have any questions or need more examples, please create a GitHub issue:
|
59 | https://github.com/nelsonic/decache/issues
|
60 |
|
61 | ***Thanks***!
|