Skip to content

komanton/cache-async

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published