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 = ; var { ... return 'Some Data';};var myData = cache; // This will call myFunction() and return 'Some Data'.var myCachedData = cache; // This will return 'Some Data' without call myFunction().
Persist data using Redis:
var cache = ; var { ... return 'Some Data';};cache;
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().
Api Reference
- cache.save(key, dataFunc)
- cache.persist(key, dataFunc, cb)
- cache.get(key)
- cache.set(key, value)