Skip to content

Commit 1e61277

Browse files
authored
Add cache layer
1 parent a8fca30 commit 1e61277

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Plugin/Url/Scope.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
class Scope
1717
{
18+
private array $cache = [];
19+
1820
public function __construct(
1921
private Config $config,
2022
private UriUtils $uriUtils
@@ -26,6 +28,15 @@ public function afterGetBaseUrl(
2628
string $type = UrlInterface::URL_TYPE_LINK,
2729
?bool $secure = null
2830
): string {
31+
return $this->cache[$subject->getId()][(int)$secure] ??= $this->processUrl($subject, $baseUrl, $type, $secure);
32+
}
33+
34+
private function processUrl(
35+
ScopeInterface $subject,
36+
string $baseUrl,
37+
string $type = UrlInterface::URL_TYPE_LINK,
38+
?bool $secure = null
39+
) {
2940
return $type === UrlInterface::URL_TYPE_LINK && $subject instanceof StoreInterface && $this->config->isEnabled()
3041
? $this->uriUtils->replaceScopeCode($baseUrl, $subject)
3142
: $baseUrl;

0 commit comments

Comments
 (0)