-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpClient] Make CachingHttpClient
compatible with RFC 9111
#59576
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
base: 7.4
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
Can we bring this to CachingHttpClient (with a BC layer) instead of introducing a new class that is the good implementation of caching but with a name that is much less clear ? |
src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
Outdated
Show resolved
Hide resolved
src/Symfony/Component/HttpClient/Tests/LegacyCachingHttpClientTest.php
Outdated
Show resolved
Hide resolved
62db76a
to
5b52dd2
Compare
UPDATE:
Otherwise, PR is ready on my side. Ready for another reviews. |
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Outdated
Show resolved
Hide resolved
b7a0bb4
to
12bf66f
Compare
e93f3b2
to
d0be468
Compare
CachingHttpClient
compatible with RFC 9111
b9df14d
to
0405dc5
Compare
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Show resolved
Hide resolved
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
b13e679
to
7c66ffd
Compare
$varyFields = $this->cache->get($varyKey, static fn (): array => []); | ||
|
||
$metadataKey = self::getMetadataKey($requestHash, $options['normalized_headers'], $varyFields); | ||
$cachedData = $this->cache->get($metadataKey, static fn (): null => null); |
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.
do we want to save the null value in the backed on a miss?
if not, we should use the $save argument passed by ref to the closure:
$cachedData = $this->cache->get($metadataKey, static fn (): null => null); | |
$cachedData = $this->cache->get($metadataKey, fn ($item, &$save) => $save = false;) |
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.
(the same concern should be consider everywhere get() is used)
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.
How does the code behave when there is 2 concurrent requests for the same URL where one request is creating the cache while the other tries to get the cache? At the bare minimum, maybe we should lock the key?
Also, maybe the implementation should take into account the fact that we could implement stale-while-revalidate
support later on.
Not sure about locking as a first step, maybe just some pointer would be enough: while writing, we use some random key name, and once the cache is populated, we update some other pointer key, this one predictably derived from the request. When the cache is stale or empty, that'd mean writing many concurrent streams to the cache backend for the same request, until one finished and wins of the others. No ideal, but at least correct from a behavioral perspective. |
https://www.rfc-editor.org/rfc/rfc9111.html