-
-
Notifications
You must be signed in to change notification settings - Fork 935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance the cache
option
#875
Comments
About #746: |
@sithmel |
Happy to implement it as soon as this is done and merged |
@szmarczak I guess I should wait for #1051 to be merged ... do you agree ? |
@sithmel You don't have to. Feel free to send a PR anytime, I'll merge with master later. No worries! :) |
Can i add another suggest feature which is kind of related to being a promise #1078 |
i've just read ky docs https://www.npmjs.com/package/ky#hooksbeforerequest
sounds quite similar for #746 needs |
@rifler It's already done. It hasn't been documented yet. |
It would be great if you can also write how can we give custom request. It's still not clear from Readme. |
@adityapatadia |
I understand the return type but I am not sure how can I return custom request function. Do you mean something like this? beforeRequest: [
async options => {
return new CacheableRequest(http.request);
}
] |
No. I mean const got = require('got');
const https = require('https');
got('https://example.com', {
hooks: {
beforeRequest: [
() => {
// `https.request` returns a ClientRequest instance
return https.request('https://httpbin.org/anything');
}
]
}
}).json(); |
You can pass an |
Understood. Thanks for help. |
No problem, if you got any other questions, feel free to ask :) |
May I know if #746 is possible yet? When remote host returns headers with |
Sorry to get back after long time but I tried this and it throws many errors related to agent and timeout.
Basically there is no easy way to just edit some part of |
@adityapatadia You're creating a new const runCachedHttps = new CacheableRequest(https.request);
const runCachedHttp = new CacheableRequest(http.request);
...
beforeRequest: [async options => {
return new Promise((resolve, reject) => {
const cr = options.url.protocol == "https:" ? runCachedHttps : runCachedHttp;
const instance = cr(options);
instance.on("request", resolve);
instance.on("error", reject);
});
}],
... |
Anything we can do to push this feature further? |
I had an issue where I couldn't trust the |
I have started working on a new cache implementation. I will let you know when I have a working example. |
Update: more than 50% RFC-compliant things finished. |
Update: I just need to finish revalidation, conditional requests, tests and we're all set ✨ |
any news on this? :) |
Sorry, been busy w/ work and uni. Will work on this asap. |
Any progress on this? I just want to be able to always cache a response...is there any hook I can use to do this? |
The same requirement. |
The
cache
mechanism:beforeCache
hook* Through the
request
option. AcceptingClientRequest
andIncomingMessage
as the return type. Returnundefined
to fallback. You can override therequest
option also by returning aClientRequest
or anIncomingMessage
instance in abeforeRequest
hook.The text was updated successfully, but these errors were encountered: