jaredwray/cacheable

Hooks should be per-instance

Closed this issue · 3 comments

Currently hooks are stored in a global context and affect all instances. Also the types have any which is incorrect.

@szmarczak - thanks we will get that fixed ASAP.

@szmarczak - when looking at the approach to do this it seems like it will be a breaking change. With that understanding I am thinking the better approach is to make cacheable request a class that can run hooks on it at an instance level.

What are your thoughts moving to that architecture with got in mind?

@szmarczak - we have moved to an updated class which takes care of the instance issue. With that said the changes will be a bit different. Here is an example:

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();

Let us know your thoughts as we are planning to release this as v9.3