Skip to content

v10.0.0

Compare
Choose a tag to compare
@jaredwray jaredwray released this 10 Sep 17:12
· 272 commits to main since this release

Breaking Change with v10.0.0

This release contains breaking changes as we are now using class to handle instances and hooks better. This is the new way to use this package.

Usage Before v10

import http from 'http';
import CacheableRequest from 'cacheable-request';

// Then instead of
const req = http.request('http://example.com', cb);
req.end();

// You can do
const cacheableRequest = new CacheableRequest(http.request);
const cacheReq = cacheableRequest('http://example.com', cb);
cacheReq.on('request', req => req.end());
// Future requests to 'example.com' will be returned from cache if still valid

// You pass in any other http.request API compatible method to be wrapped with cache support:
const cacheableRequest = new CacheableRequest(https.request);
const cacheableRequest = new CacheableRequest(electron.net);

Usage After v10

import CacheableRequest from 'cacheable-request';

// Now You can do
const cacheableRequest = new CacheableRequest(http.request).createCacheableRequest();
const cacheReq = cacheableRequest('http://example.com', cb);
cacheReq.on('request', req => req.end());
// Future requests to 'example.com' will be returned from cache if still valid

// You pass in any other http.request API compatible method to be wrapped with cache support:
const cacheableRequest = new CacheableRequest(https.request).createCacheableRequest();
const cacheableRequest = new CacheableRequest(electron.net).createCacheableRequest();

The biggest change is that when you do a new CacheableRequest you now want to call createCacheableRequest method will give you the instance to use.

- const cacheableRequest = new CacheableRequest(http.request);
+ const cacheableRequest = new CacheableRequest(http.request).createCacheableRequest();

What's Changed

New Contributors

Full Changelog: v9.0.0...v10.0.0