1.0.3 • Published 4 years ago

hs-cache-request-promise v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

hs-cache-request-promise

A simple NodeJS cache version of request-promise.

Notice

  • Only supports predefined getJson() request at the moment.

Install

npm install hs-cache-request-promise

Initialize

By default cache requests for 10 seconds and do not use file storage.

const Request = require('hs-cache-request-promise');
const request = new Request({ttl: 60000, dir: './cache/folder'});

Example

request.getJson('https://api.url...').then(function(res) {
    console.log(res);    // api json response
});

To use option parameters:

request.getJson('https://api.url...', { headers: { 'User-Agent': 'Request-Promise' }}).then(function(res) {
    console.log(res);
});

request.getJson('https://api.url...', { timeout: 30000 }).then(function(res) {
    console.log(res);
});

// get response from cache only. returns `null` if expired or does not exist.
request.getJson('https://api.url...', { cacheOnly: true }).then(function(res) {
    console.log(res);
});
1.0.3

4 years ago

1.0.2

5 years ago