Repository navigation
clients(php): cache host state only on change - #7202
Merged
Fluf22 merged 4 commits intoOct 28, 2026
Merged
Conversation
algolia-api-clients-automation-bot Bot
added a commit
that referenced
this pull request
Oct 28, 2026
β¦ip ci] Co-authored-by: Masatoshi Ogiwara <msts.oo0131@gmail.com>
algolia-api-clients-automation-bot Bot
added a commit
to algolia/algoliasearch-client-csharp
that referenced
this pull request
Oct 28, 2026
algolia/api-clients-automation#7202 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Masatoshi Ogiwara <msts.oo0131@gmail.com>
algolia-api-clients-automation-bot Bot
added a commit
to algolia/algoliasearch-client-dart
that referenced
this pull request
Oct 28, 2026
algolia/api-clients-automation#7202 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Masatoshi Ogiwara <msts.oo0131@gmail.com>
algolia-api-clients-automation-bot Bot
added a commit
to algolia/algoliasearch-client-go
that referenced
this pull request
Oct 28, 2026
algolia/api-clients-automation#7202 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Masatoshi Ogiwara <msts.oo0131@gmail.com>
algolia-api-clients-automation-bot Bot
added a commit
to algolia/algoliasearch-client-java
that referenced
this pull request
Oct 28, 2026
algolia/api-clients-automation#7202 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Masatoshi Ogiwara <msts.oo0131@gmail.com>
algolia-api-clients-automation-bot Bot
added a commit
to algolia/algoliasearch-client-javascript
that referenced
this pull request
Oct 28, 2026
algolia/api-clients-automation#7202 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Masatoshi Ogiwara <msts.oo0131@gmail.com>
algolia-api-clients-automation-bot Bot
added a commit
to algolia/algoliasearch-client-kotlin
that referenced
this pull request
Oct 28, 2026
algolia/api-clients-automation#7202 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Masatoshi Ogiwara <msts.oo0131@gmail.com>
algolia-api-clients-automation-bot Bot
added a commit
to algolia/algoliasearch-client-php
that referenced
this pull request
Oct 28, 2026
algolia/api-clients-automation#7202 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Masatoshi Ogiwara <msts.oo0131@gmail.com>
algolia-api-clients-automation-bot Bot
added a commit
to algolia/algoliasearch-client-python
that referenced
this pull request
Oct 28, 2026
algolia/api-clients-automation#7202 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Masatoshi Ogiwara <msts.oo0131@gmail.com>
algolia-api-clients-automation-bot Bot
added a commit
to algolia/algoliasearch-client-ruby
that referenced
this pull request
Oct 28, 2026
algolia/api-clients-automation#7202 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Masatoshi Ogiwara <msts.oo0131@gmail.com>
algolia-api-clients-automation-bot Bot
added a commit
to algolia/algoliasearch-client-scala
that referenced
this pull request
Oct 28, 2026
algolia/api-clients-automation#7202 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Masatoshi Ogiwara <msts.oo0131@gmail.com>
algolia-api-clients-automation-bot Bot
added a commit
to algolia/algoliasearch-client-swift
that referenced
this pull request
Oct 28, 2026
algolia/api-clients-automation#7202 Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com> Co-authored-by: Masatoshi Ogiwara <msts.oo0131@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ClusterHosts::resetHost()is called after every successful request and always writes the host state to the cache, even when the host was already up and had no timeouts to clear. This PR only writes the cache when the reset actually changes a host.π§ What and Why
When a cache is set with
Algolia::setCache(), every successful request runsupdateCache(), which serializes the wholeClusterHostsand callsset()on the cache, although in most cases nothing changed.Depending on the cache, that is one extra network round trip (f.e Redis) or one file write per request.
It also means processes sharing the same cache key keep overwriting each other's host state with writes that carry no change.
Changes included:
Host::reset()returns whether the host state changed: it was down, or its retry count was not0(a host that timed out but is still up).HostCollection::resetHost()returns whether any matching host changed (array_mapreplaced byforeachto collect the result).ClusterHosts::resetHost()resets both the read and write collections, then callsupdateCache()only when one of them changed.Host::reset()ignore the return value, so their behavior does not change.π§ͺ Test
Plans
Add
tests/output/php/src/manual/HostStateCacheTest.php, which swaps in a PSR-16 cache that countsset()liketestResetOfAHealthyHostDoesNotWriteTheCache: resetting a host that is up with no retries does not write the cache.testResetOfAChangedHostWritesTheCache: resetting a host that was marked down, or that timed out, still writes the cache.testSuccessfulRequestsOnAHealthyHostDoNotWriteTheCache: successful requests on a healthy host do not write the cache.testSuccessAfterATimeoutWritesTheCacheOnce: after a timeout, the next success on that host writes the cache once, and later successes do not.Results
Notes
ClusterHosts::createFromCache()still calls@unserialize()withoutallowed_classes, so whoever can write to the cache (for example a shared Redis) can make it create objects of any class.However, this PR does not change that.
Because I think it will be handled in a separate PR by restricting it to
['allowed_classes' => [ClusterHosts::class, HostCollection::class, Host::class]].