Home

Awesome

CachedFs

Wrap node.js' fs module in a cached read-only version that exposes the same interface. Can speed up things if you're reading the same files and directories multiple times, and things don't change on disc.

Doesn't expose the functions that write to disc, so no cache invalidation is ever performed internally.

var CachedFs = require('cachedfs'),
    fs = new CachedFs();

fs.readFile('foo.txt', function (err, contents) {
    fs.readFile('foo.txt', function (err, contentsAgain) {
        // Much faster this time!
    });
});

You can also patch the built-in fs module or a compatible one in-place (this should be considered a bit experimental):

require('cachedfs').patchInPlace();

require('fs').readFile('foo.txt', function (err, contents) {
    // Yup, this will be cached!
});

The CachedFs constructor and CachedFs.patchInPlace support an options object with the following properties:

If you don't specify a length option, it will default to a function that approximates the number of bytes occupied by the cached values. That means you can use the max option to set an upper limit on the memory usage in bytes:

var CachedFs = require('cachedfs'),
    cachedFs = new CachedFs({max: 104857600});

or when patching the built-in fs module in-place:

var CachedFs = require('cachedfs');

CachedFs.patchInPlace({max: 104857600});

An instantiated CachedFs has the following properties:

Supported methods:

Bonus features:

Installation

Make sure you have node.js and npm installed, then run:

npm install cachedfs

License

3-clause BSD license -- see the LICENSE file for details.