Skip to content
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

Only use one network request when identical requests are made #3232

Open
jeswr opened this issue May 9, 2024 · 6 comments
Open

Only use one network request when identical requests are made #3232

jeswr opened this issue May 9, 2024 · 6 comments
Labels
enhancement New feature or request interceptors Pull requests or issues related to Dispatcher Interceptors

Comments

@jeswr
Copy link

jeswr commented May 9, 2024

This would solve...

Performance and robustness issues associated with fetching the same HTTP resource in parallel in several places across a codebase.

The implementation should look like...

Using an interceptor, keep an internal record of pending requests, if an identical request is already pending re-use the response across the multiple pending requests

Additional context

Originally raised in #3221, related to #3231

@jeswr jeswr added the enhancement New feature or request label May 9, 2024
@mcollina
Copy link
Member

The hardest part of this is what is considered an indentical request.

Overall, this would be a nice interceptor to add.

@metcoder95
Copy link
Member

I'd suggest starting with an idempotent request by default and its request for fingerprint for checking identity, and verifying its response with a possible timeout to invalidate the cached responses.

Also some hooks similar to what we did for retry interceptor so implementations can customize the behaviour for validating if two requests are identical.

@metcoder95 metcoder95 added the interceptors Pull requests or issues related to Dispatcher Interceptors label May 12, 2024
@Uzlopak
Copy link
Contributor

Uzlopak commented May 12, 2024

In rfc 9111 it actually defines requests where the http cache should return the same cached response. This definition could be used.

@Uzlopak
Copy link
Contributor

Uzlopak commented May 12, 2024

Btw. How do you handle streams?

@metcoder95
Copy link
Member

True, this can help provide some guidance for defaults: https://www.rfc-editor.org/rfc/rfc9111.html#name-storing-responses-in-caches

I'd just still be mindful of providing some control to the implementation.

Btw. How do you handle streams?

wdym?

@ronag
Copy link
Member

ronag commented May 12, 2024

With streams you can have multiple consumers consuming the response with different speeds. We should only do this for requests where the response body can be fully buffered into memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request interceptors Pull requests or issues related to Dispatcher Interceptors
Projects
None yet
Development

No branches or pull requests

5 participants