Skip to content

fix: call buildInitial() before cacheKey() in toBase64() to prevent extra cache entries#184

Open
Copilot wants to merge 4 commits into
masterfrom
copilot/631-fix-tobase64-caching
Open

fix: call buildInitial() before cacheKey() in toBase64() to prevent extra cache entries#184
Copilot wants to merge 4 commits into
masterfrom
copilot/631-fix-tobase64-caching

Conversation

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown

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

  • Bug Fix: In src/Avatar.php, buildInitial() is now called before cacheKey() inside toBase64(), ensuring the cache key correctly incorporates the generator-produced initials.
  • Regression Test: Added it_uses_computed_initials_in_cache_key_for_to_base64 in tests/AvatarPhpTest.php to assert that toBase64() calls cache->get() with a key derived from the computed initials, preventing this issue from reappearing.

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
Copilot AI requested a review from qisthidev June 10, 2026 18:34
@qisthidev qisthidev marked this pull request as ready for review June 11, 2026 02:08
Copilot AI review requested due to automatic review settings June 11, 2026 02:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in toBase64().
  • Align toBase64()’s initialization flow with the existing toSvg() pattern.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Avatar.php
Comment on lines +205 to 207
$this->buildInitial();

$key = $this->cacheKeyPrefix.$this->cacheKey();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6.3.1 and 6.4.0 - toBase64(), uninitilized $initials, caching - Extra cache entries

3 participants