Skip to content

Commit 1b06332

Browse files
authored
fix(core): allow discovery:generate to run even when full caching is enabled (#1223)
1 parent 014b67f commit 1b06332

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

packages/cache/src/CacheConfig.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(
3535
/** Used as a global override, should be true in production, null in local */
3636
?bool $enable = null,
3737
) {
38-
$this->enable = $enable ?? env('CACHE');
38+
$this->enable = $this->enableCache($enable);
3939
$this->iconCache = (bool) env('ICON_CACHE', true);
4040
$this->projectCache = (bool) env('PROJECT_CACHE', false);
4141
$this->viewCache = (bool) env('VIEW_CACHE', false);
@@ -51,12 +51,8 @@ public function addCache(string $className): void
5151

5252
private function resolveDiscoveryCacheStrategy(): DiscoveryCacheStrategy
5353
{
54-
if (PHP_SAPI === 'cli') {
55-
$command = $_SERVER['argv'][1] ?? null;
56-
57-
if ($command === 'dg' || $command === 'discovery:generate') {
58-
return DiscoveryCacheStrategy::NONE;
59-
}
54+
if ($this->isDiscoveryGenerateCommand()) {
55+
return DiscoveryCacheStrategy::NONE;
6056
}
6157

6258
$cache = env('CACHE');
@@ -79,4 +75,24 @@ private function resolveDiscoveryCacheStrategy(): DiscoveryCacheStrategy
7975

8076
return $current;
8177
}
78+
79+
private function enableCache(?bool $enable): ?bool
80+
{
81+
if ($this->isDiscoveryGenerateCommand()) {
82+
return false;
83+
}
84+
85+
return $enable ?? env('CACHE');
86+
}
87+
88+
private function isDiscoveryGenerateCommand(): bool
89+
{
90+
if (PHP_SAPI !== 'cli') {
91+
return false;
92+
}
93+
94+
$command = $_SERVER['argv'][1] ?? null;
95+
96+
return $command === 'dg' || $command === 'discovery:generate';
97+
}
8298
}

0 commit comments

Comments
 (0)