Skip to content

Releases: jaredwray/cacheable

v10.0.0

10 Sep 17:12
Compare
Choose a tag to compare

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

v9.0.0

13 Aug 16:00
364d726
Compare
Choose a tag to compare

v9 is now pure ESM 🎉

cacheable-request is now pure ESM with version v9.0.0 and up. Version v.8.x.x is the supported commonjs version which will get only major security fixes moving forward until end of 2022. If you would like to learn about uprgrading / using ESM @sindresorhus has an amazing reference guide here: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

Major thank you to @alphmth, @sindresorhus, @szmarczak, @jasonbaik, and everybody for help on this. 🙌

Special call out to @CyberShadow as in the previous release we forgot to mention the work done on issue #28 as without their guidance and code we wouldn't have fixed it. ❤️

Typescript

In addition to pure ESM we are now fulling using Typescript moving forward on this project which means all type definitions are now native with the service. 🤩

Hooks!

Hooks have been introduced for the response object that will run a processing function like so if you wanted to do compression:

CacheableRequest.addHook('response', async (response: any) => {
  const buffer = await pm(gunzip)(response);
  return buffer.toString();
});

const cacheableRequest = CacheableRequest(request, cache);

How to Add a Hook: https://github.com/jaredwray/cacheable-request#add-hooks
How to Remove a Hook: https://github.com/jaredwray/cacheable-request#remove-hooks

We would love some feedback on this feature!

Change Log

Full Changelog: v8.3.1...v9.0.0

v8.3.1

27 Jun 15:50
Compare
Choose a tag to compare

What's Changed

Full Changelog: v8.0.1...v8.3.1

v8.0.1

11 Jun 18:40
4192f5e
Compare
Choose a tag to compare

What's Changed

Full Changelog: v8.0.0...v8.0.1

v8.0.0

11 Jun 18:11
f072ad6
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v7.0.2...v8.0.0

v7.0.2

09 Jun 11:21
Compare
Choose a tag to compare
7.0.2