-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add request deduplication and caching in client #151
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some minor changes needed, and a question
packages/client/src/index.ts
Outdated
* | ||
* ### Caching | ||
* | ||
* By default, the client caches responses in browser environments for a duration of 5 minutes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change this to more accurately state that we set the x-cache-expires
header on the response which only works in environments that respsect it (i.e. browsers)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x-cache-expires
is just an arbitrary name. The browser doesn't inspect it.
Instead, we inspect it when reading from the cache:
I've refined the wording to reflect this more accurately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm!
|
||
// Clear the cache when stopping | ||
if (this.cache != null) { | ||
void this.cache.delete('delegated-routing-v1-cache') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realised that this can be a problem if you have multiple instances of the client in scope as we do in Verified Fetch.
But even then, it's most likely that they all get stopped at the same time rather than individually.
## [@helia/delegated-routing-v1-http-api-client-v4.2.0](https://github.com/ipfs/helia-delegated-routing-v1-http-api/compare/@helia/delegated-routing-v1-http-api-client-4.1.2...@helia/delegated-routing-v1-http-api-client-4.2.0) (2024-11-11) ### Features * request deduplication and caching in client ([#151](#151)) ([98105ae](98105ae)), closes [#148](#148)
🎉 This PR is included in version @helia/delegated-routing-v1-http-api-client-v4.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Title
Fix #148.
By default, caching is enabled with TTL as specified in https://specs.ipfs.tech/routing/http-routing-v1/#response-headers
Description
Notes & open questions
How to make sure we run tests in browser with an echo server in node.jsChange checklist