fix: call buildInitial() before cacheKey() in toBase64() to prevent extra cache entries#184
Open
Copilot wants to merge 4 commits into
Open
fix: call buildInitial() before cacheKey() in toBase64() to prevent extra cache entries#184Copilot wants to merge 4 commits into
Copilot wants to merge 4 commits into
Conversation
…xtra cache entries
Copilot
AI
changed the title
[WIP] Fix caching issue in toBase64 with uninitialized initials
Fix: call buildInitial() before cacheKey() in toBase64() to prevent extra cache entries
Jun 10, 2026
There was a problem hiding this comment.
Pull request overview
This PR fixes a caching key inconsistency in Avatar::toBase64() by ensuring initials are generated before the cache key is computed, preventing cache misses and redundant cache entries when caching is enabled.
Changes:
- Call
buildInitial()before computing the cache key intoBase64(). - Align
toBase64()’s initialization flow with the existingtoSvg()pattern.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+205
to
207
| $this->buildInitial(); | ||
|
|
||
| $key = $this->cacheKeyPrefix.$this->cacheKey(); |
Author
There was a problem hiding this comment.
Added regression test it_uses_computed_initials_in_cache_key_for_to_base64 in tests/AvatarPhpTest.php. It uses reflection to compute the expected cache key with FooGenerator-produced initials ('foo'), then mocks the cache repository to assert that get() is called with exactly that key — ensuring buildInitial() runs before cacheKey() in toBase64().
Copilot
AI
changed the title
Fix: call buildInitial() before cacheKey() in toBase64() to prevent extra cache entries
fix: call buildInitial() before cacheKey() in toBase64() to prevent extra cache entries
Jun 11, 2026
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.
Fixes a cache-duplication bug where
toBase64()computed the cache key before the initials were built, causing each call to produce a unique key (with empty initials) and bypassing the cache entirely.Changes Made
src/Avatar.php,buildInitial()is now called beforecacheKey()insidetoBase64(), ensuring the cache key correctly incorporates the generator-produced initials.it_uses_computed_initials_in_cache_key_for_to_base64intests/AvatarPhpTest.phpto assert thattoBase64()callscache->get()with a key derived from the computed initials, preventing this issue from reappearing.