Socket
Socket
Sign inDemoInstall

io-cache

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    io-cache

Cache external resources


Version published
Maintainers
1
Install size
8.00 kB
Created

Readme

Source

IOCache

Cache external resources easily.

Most generic in-memory caching modules require statements like:

if (cache.contains(filename)) {
    callback(cache.get(filename));
} else {
    fs.readFile(filename, function (err, contents) {
        cache.set(key, contents);
        callback(contents);
    });
}

If you're using them, you should probably set up a helper to prevent such statements being littered all over the place.

IOCache is your helper. Set up an IOCache with it's external resource from the start:

var cachedFs = new IOCache(fs.readFile);

Then read the arguments from the first call every time:

cachedFs.get(filename, function (err, contents) {
    if (!err) {
        callback(contents);
    }
});

IOCache will sort out working out whether or not it's cached. It's always async, just so you know.

TODO

  • Expire items in cache. Currently this can be done with delete cachedFS.cache[filename], but there should be a better way.

FAQs

Last updated on 31 May 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc