From 3f06ec42ac45edddba57544241ee5ea754aa88c5 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 5 Jun 2026 16:41:12 +0200 Subject: [PATCH] perf(icon): skip redundant cache read --- packages/icon/src/Icon.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/icon/src/Icon.php b/packages/icon/src/Icon.php index 8efcbf076b..434d4895ed 100644 --- a/packages/icon/src/Icon.php +++ b/packages/icon/src/Icon.php @@ -34,16 +34,20 @@ public function render(string $icon): ?string return null; } + $fetched = false; $svg = $this->iconCache->resolve( key: "icon-{$collection}-{$iconName}", - callback: fn () => $this->fetchSvg($collection, $iconName), + callback: function () use ($collection, $iconName, &$fetched) { + $fetched = true; + + return $this->fetchSvg($collection, $iconName); + }, expiresAt: $this->iconConfig->expiresAfter, ); - /** @var bool $failed */ - $failed = $this->iconCache->get("icon-failure-{$collection}-{$iconName}"); - - if ($failed) { + // fetchSvg() returns null only on failure, and resolve() will have cached + // that null — drop it so a retry can happen once the failure marker expires. + if ($fetched && $svg === null) { $this->iconCache->delete("icon-{$collection}-{$iconName}"); }