cache-throttle
Provides caching and throttling of promises.
- cachify(func, options) - Returns the function wrapped with caching
- cachifyAll(target, options) - Patches all the target's methods with caching
- throttlify(func, options) - Returns the function wrapped with throttling
- throttlifyAll(target, options) - Patches all the target's methods with throttling
These have similar definitions to bluebird's promisify:
- cachify and throttlify resemble bluebird's promisify
- cachifyAll and throttlifyAll resemble bluebird's promisifyAll
You can also use the underlying functions directly:
- throttler.throttleAsync(func) - Limits the number of concurrent calls. Any additional calls will wait.
- lockableCache.callAsync(key, func) - Ensures a function isn't called concurrently. Any subsequent calls with same key before the first has resolved will wait and receive the same response.
Examples
npm install cache-throttle
var cacheThrottle = ;var Promise = ;var superagent = ;var agent = superagent Promise; var API = { return agent; } { return agent; } { return agent; }; cacheThrottle;cacheThrottle;// NOTE: throttling should be applied before caching
Or for single functions:
var getDriversAsyncThrottled = cacheThrottle;var getDriversAsyncCached = cacheThrottle;
To apply throttlify with the same throttler:
var throttler = /* optional */ concurrency: 1 queueLimit: 100;var getDriversAsyncThrottled = cacheThrottle;var getUsersAsyncThrottled = cacheThrottle;cacheThrottle;
Or use LockableCache
and Throttler
directly:
var throttler = /* optional */ concurrency: 1 queueLimit: 100;var lockableCache = ; lockableCache;