Closed levino closed 7 years ago
Hi @Levino, take a look at throttled-request. You can do something like this:
var request = require('request');
var throttledRequest = require('throttled-request')(request);
throttledRequest.configure({requests: 1, milliseconds: 1000}); //send 1 request per second
var cachedRequest = require('cached-request')(throttledRequest);
cachedRequest.setCacheDirectory(cacheDirectory);
Then use cachedRequest
to perform your requests. Only requests that are not in the cache will be throttled.
Of course! Thank you for the detailed reply.
I am using the library to query data (and cache it) from fixer.io. Fixer.io is rate limited. So I would like to throttle requests to the api but ONLY if the data is not read from cache. Is there any way on hooking up into the case when there is cache miss?