Skip to content

maxcnunes/promise-async-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

promise-async-cache

Build Status npm version

Thanks @esnunes for the initial implementation :)

Installation

Install via npm:

$ npm install promise-async-cache

Usage

// the example uses es6 but it works with es5 as well
import PromiseAsyncCache from 'promise-async-cache';

// loading value into the cache
const cache = new PromiseAsyncCache({
  load (key) {
    // load async data
    // then return a promise with the value to be cached
  }
});

// getting value from the cache
cache.get(key).then(value => /* ... */);

Extra arguments

Is possible passing extra arguments to the load function through the get function:

const cache = new PromiseAsyncCache({
  load (key, myOtherObject) { /* ... */ }
});

cache.get(key, myOtherObject).then(value => /* ... */);

It is required to use editorconfig and please write and run specs before pushing any changes:

npm test

License

Copyright (c) 2015 Max Claus Nunes. This software is licensed under the MIT License.

About

Simple lib to cache data through async load process.

Resources

License

Stars

Watchers

Forks

Packages

No packages published