cacheable

Wrap native HTTP requests with RFC compliant cache support

MIT License

Downloads
390.9M
Stars
286
Committers
82

Bot releases are visible (Hide)

cacheable - Release 5.1.1

Published by zzau13 about 2 years ago

5.1.1 (2022-10-19)

Bug Fixes

  • bad Cache definition (3746c39)
  • mget/mset examples in README (1ca67a4)
cacheable - Release 5.1.0

Published by zzau13 about 2 years ago

5.1.0 (2022-10-19)

Features

  • add ttl argument in wrap method (b06c1e5)
cacheable - v10.2.1

Published by jaredwray about 2 years ago

10.2.1 Bug fixes and Changes

Biggest change has been that when an agent is KeepAlive: true we are now sending a response end which will close the socket instead of an error.

What's Changed

New Contributors

Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v10.2.0...v10.2.1

cacheable - v10.2.0

Published by jaredwray about 2 years ago

Hooks onResponse replacing response hook

response will still work but will be deprecated as we expand this functionality. onResponse will be the name moving forward. Here are examples of how to use it.

How to decompress

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

const cacheableRequest = new CacheableRequest(request, cache).request();

// adding a hook to decompress response
cacheableRequest.addHook('onResponse', async (value: CacheValue, response: any) => {
  const buffer = await pm(gunzip)(value.body);
  value.body = buffer.toString();
  return value;
});

how to add a remote address

import CacheableRequest, {CacheValue} from 'cacheable-request';

const cacheableRequest = new CacheableRequest(request, cache).request();
cacheableRequest.addHook('onResponse', (value: CacheValue, response: any) => {
  if (response.connection) {
    value.remoteAddress = response.connection.remoteAddress;
  }

  return value;
});

In addition to that we have also updated some of the packages to their lates which you can read below 👇

What's Changed

Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v10.1.2...v10.2.0

cacheable - v10.1.2

Published by jaredwray about 2 years ago

⚠️ Breaking Change

Based on feedback (thanks @szmarczak!) we have renamed the function createCacheableRequest to just request.

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

v10 code with createCacheableRequest

import CacheableRequest from 'cacheable-request';

// Now You can do
const cacheableRequest = new CacheableRequest(http.request).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).createCacheableRequest();
const cacheableRequest = new CacheableRequest(electron.net).createCacheableRequest();

v10.1.2 code with request

import CacheableRequest from 'cacheable-request';

// Now You can do
const cacheableRequest = new CacheableRequest(http.request).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).request();
const cacheableRequest = new CacheableRequest(electron.net).request();

What's Changed

Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v10.0.2...v10.1.2

cacheable - v10.0.2

Published by jaredwray about 2 years ago

Change to support got by exporting types enabling better integration with upstream packages.

What's Changed

Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v10.0.1...v10.0.2

cacheable - v10.0.1

Published by jaredwray about 2 years ago

Minor maintenance release with some primary packages updated such as:

  • @types/node to 18.7.16
  • keyv to 4.5.0
  • normalize-url to 7.10

Changelog

Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v10.0.0...v10.0.1

cacheable - v10.0.0

Published by jaredwray about 2 years ago

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: https://github.com/jaredwray/cacheable-request/compare/v9.0.0...v10.0.0

cacheable - v9.0.0

Published by jaredwray about 2 years ago

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: https://github.com/jaredwray/cacheable-request/compare/v8.3.1...v9.0.0

cacheable - v8.3.1

Published by jaredwray over 2 years ago

cacheable - v8.0.1

Published by jaredwray over 2 years ago

What's Changed

Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v8.0.0...v8.0.1

cacheable - v8.0.0

Published by jaredwray over 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/jaredwray/cacheable-request/compare/v7.0.2...v8.0.0

cacheable -

Published by szmarczak over 3 years ago

Package Rankings
Top 31.99% on Repo1.maven.org
Top 0.88% on Npmjs.org
Badges
Extracted from project README
tests codecov npm npm npm npm npm npm npm npm npm npm npm npm npm