lazycache

0.0.2 • Public • Published

lazycache

lazy inmemory cache for node, automatic reset cache asynchronously when expired

NPM

Build Status Coverage Status

Install

npm i lazycache --save

Usage

lazyCache()

Use the factory method to init a cache object:

var defaultCacheTime = 300000; // 300000 ms = 5 min
var cache = require('lazyCache')(defaultCacheTime);

if defaultCacheTime < 0, a noCache object will return, which offer the same API but do NOT cache anything.

cache.get(key)

Get value from cache

  • key: cache key
cache.set('key', 'my cache value');

cache.set(key, val [, cacheTime] [, reseter])

Set value into cache

  • key: cache key
  • val: cache value
  • cacheTime: cache time (ms)
  • reseter: a function which reset the cache value
var reseter = function (cb) {
    // async
    setTimeout(function () {
        cb(null, 'new value'); // `null` for NO error
    }, 30);
};
cache.set('key', 'initial value', reseter)

Readme

Keywords

Package Sidebar

Install

npm i lazycache

Weekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • csbun