cache-resolver

0.1.3 • Public • Published

CacheResolver

Summary

In-memory cache to retrieve and set values based on promise resolution.

Usage

Node.js

Install to your project using npm:

npm install cache-resolver --save-dev

Use it:

var CacheResolver = require('cache-resolver');
var cache = new CacheResolver();
 
// first resolve, uses callback to resolve promise and save in cache
cache.resolve({
  key: 'cache-key',
  callback: function() {
    return new Promise(function(resolve, reject) {
      // perform some asynchronous operation
      setTimeout(function() {
        resolve('success');
      }, 500);
    });
  }
}).then(function(result) {
  console.log(result); // 'success'
});
 
// second resolve, run in parallel to first, reuses first callback promise
cache.resolve({
  key: 'cache-key',
  callback: function() {
    return new Promise(function(resolve, reject) {
      // perform some asynchronous operation
      setTimeout(function() {
        resolve('callback will not be used');
      }, 500);
    });
  }
}).then(function(result) {
  console.log(result); // 'success'
});

Browser

Browser distribution files are checked into github with the source. See Document bundles for details on which bundle is right for you.

API

See API Documentation.

Contribute

See Contribution Documentation.

Package Sidebar

Install

npm i cache-resolver

Weekly Downloads

3

Version

0.1.3

License

MIT

Last publish

Collaborators

  • coreyferguson