Skip to content

Latest commit

 

History

History
40 lines (32 loc) · 878 Bytes

README.md

File metadata and controls

40 lines (32 loc) · 878 Bytes

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