Skip to content

Commit 88594df

Browse files
authored
perf(icon): skip redundant cache read (#2160)
1 parent 3e4c725 commit 88594df

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

packages/icon/src/Icon.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,20 @@ public function render(string $icon): ?string
3434
return null;
3535
}
3636

37+
$fetched = false;
3738
$svg = $this->iconCache->resolve(
3839
key: "icon-{$collection}-{$iconName}",
39-
callback: fn () => $this->fetchSvg($collection, $iconName),
40+
callback: function () use ($collection, $iconName, &$fetched) {
41+
$fetched = true;
42+
43+
return $this->fetchSvg($collection, $iconName);
44+
},
4045
expiresAt: $this->iconConfig->expiresAfter,
4146
);
4247

43-
/** @var bool $failed */
44-
$failed = $this->iconCache->get("icon-failure-{$collection}-{$iconName}");
45-
46-
if ($failed) {
48+
// fetchSvg() returns null only on failure, and resolve() will have cached
49+
// that null — drop it so a retry can happen once the failure marker expires.
50+
if ($fetched && $svg === null) {
4751
$this->iconCache->delete("icon-{$collection}-{$iconName}");
4852
}
4953

0 commit comments

Comments
 (0)