1.0.3 • Published 8 years ago

cache-async v1.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

cache-async

A small module providing cache for async methods with promises

Installation

  npm install cache-async --save

Usage

var Cache = require('cache-async');
var asyncWaiter = setTimeout;
var cache = Cache(asyncWaiter);

var cacheTimeoutMilliseconds = 10000;
  
cache.get('key_1', function(){
        return new Promise(function(resolve, reject) {
            //Example long async operation
            console.log('async start ...');
            setTimeout(function() {
                console.log('async end!');                
                resolve(1);                
            }, 5000);
        });
    }, cacheTimeoutMilliseconds).then(function(keyValue){
        console.log(keyValue.key + ' ' + keyValue.value); //key_1 1
    });

Tests

  npm test

Contributing

Release History

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago