4.0.0 • Published 6 years ago

@ryanburnette/request-cache v4.0.0

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

@ryanburnette/request-cache

Add caching mechanisms to your favorite HTTP request library.

Request Libraries

Choose your preferred library that provides HTTP request functionality. Some are supported now, others are on the roadmap.

At the moment, callback-based libraries must be converted to Promises using util.promisify.

Caching Mechanisms

Library Options

Library options take precedence over all other caching mechanisms. For example, if the Expires header sets an expiration time of one hour from now, but the minAge option is set to two hours, the Expires header will be ignored and a subsequent request will not be made until the two hours has elapsed. If minAge were set to 30 minutes, the Expires header would be respected. This logic is reversed for maxAge.

Expires Header

The Expires header is respected unless minAge or maxAge is less or more restrictive as appropriate.

Installation

npm install @ryanburnette/request-cache

You'll need to install and include a request library. Libraries structured using callbacks should be promisified.

npm install --save @root/request

Usage

var util = require('util');
var RequestCache = require('@ryanburnette/request-cache');

var request = RequestCache.create({
  request: util.promisify(require('@root/request'))
});

request({ url: 'https://example.com/api/items' })
  .then(function (resp) {
    console.log(resp.statusCode);
  });

console.log(request.cachedUrls);

request.clearCache('https://example.com/api/items');

Development/Testing

Tests are writting in Jest, but the library is not saved to devDependencies. Install request library and test library manually for development.

npm install --no-save @root/request jest

Then watch for changes, rerunning tests.

npm run test -- --watch
4.0.0

6 years ago

3.1.0

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago