nodecache

Simple and powerful Cache Module for NodeJS. =============

Usage no npm install needed!

<script type="module">
  import nodecache from 'https://cdn.skypack.dev/nodecache';
</script>

README

Simple and powerful Cache Module for NodeJS.

Install with:

npm install nodecache

Usage

Save data in memory, the second parameter of cache.save only be called if it is not currently in memory.

    var cache = require('nodecache');

    var myFunction = function () {
        ...
        return 'Some Data';
    };
    var myData = cache.save('myData', myFunction); // This will call myFunction() and return 'Some Data'.
    var myCachedData = cache.save('myData', myFunction); // This will return 'Some Data' without call myFunction().

Persist data using Redis:

    var cache = require('nodecache');

    var myFunction = function () {
        ...
        return 'Some Data';
    };
    cache.persist('myData', myFunction, function (err, reply) {
        console.log(reply); // Some Data
    });

In the code above, data will be searched first in local memory, if not found there, it will be searched on Redis Storange, and if neither, it finally call myFunction().