Skip to content

Limit the number of calls to a function by caching the results of execution

License

Notifications You must be signed in to change notification settings

d-vova/vs-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vs-cache

Limit the number of calls to a function by caching the results of execution

Installation

npm install vs-cache

Quick Start

First, define an asynchronous function that should be cached:

var task = function task ( callback ) {
  var execute = function ( ) {
    callback(null, new Date().getTime());
  }
  
  var timeout = 10 * Math.random() | 0;
  
  setTimeout(execute, timeout);
}

Second, use cache to retrieve the result of running the task

var cache = require('vs-cache');

var cachedTask = cache.create(task, 50);

cachedTask.retrieve(function callback ( error, value ) {
  console.log('retrieved result: ' + String(error || value));
});

License

MIT

About

Limit the number of calls to a function by caching the results of execution

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published