Skip to content

A utility to maintain an always warm cache refreshed every x seconds

Notifications You must be signed in to change notification settings

jmilagroso/keep-warm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

keep-warm

GitHub version NPM Version

Deps Dev Deps Peer Deps

NPM Downloads GitHub stars GitHub forks GitHub issues

A utility to maintain an always warm cache refreshed every x seconds

npm install --save keep-warm

Basic example:

var keepWarm = require('keep-warm');

/* Params:
 * key: a unique string
 * fetch: a function returning a Promise
 * interval: cache will be updated every interval ms
 */
keepWarm('myKey', function() {
    // does something async and returns a Promise
}, 15000);

/* Params
 * key: the key you originally passed to keepWarm
 * Use when you want the data synchronously and don't care about a failure when the cache has not been initially populated
 */
var myData = keepWarm.get('myKey');

/* Params
 * key: the key you originally passed to keepWarm
 * Use when you want to wait for the cache to be populated if it's not
 */
var myData;
keepWarm.getAsync('myKey').then(function(value) {
    myData = value;
});

Note: This relies on the existence of a global Promise object as defined in the ECMAScript 6 (Harmony) proposal.

About

A utility to maintain an always warm cache refreshed every x seconds

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%