Skip to content

Commit

Permalink
chore(core): discovery cache improvements (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidan-casey committed Nov 25, 2024
1 parent 6941bea commit 5b298b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
15 changes: 1 addition & 14 deletions src/Commands/DiscoveryGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
{
use HasConsole;

public const string CURRENT_DISCOVERY_STRATEGY = __DIR__ . '/../.cache/current_discovery_strategy';

public function __construct(
private Kernel $kernel,
private DiscoveryCache $discoveryCache,
Expand All @@ -45,7 +43,7 @@ public function __invoke(): void

$this->generateDiscoveryCache($strategy);

$this->storeDiscoveryCacheStrategy($strategy);
$this->discoveryCache->storeStrategy($strategy);
}

public function clearDiscoveryCache(): void
Expand Down Expand Up @@ -100,17 +98,6 @@ private function resolveDiscoveryCacheStrategy(): DiscoveryCacheStrategy
return DiscoveryCacheStrategy::make(env('DISCOVERY_CACHE'));
}

private function storeDiscoveryCacheStrategy(DiscoveryCacheStrategy $strategy): void
{
$dir = dirname(self::CURRENT_DISCOVERY_STRATEGY);

if (! is_dir($dir)) {
mkdir($dir, recursive: true);
}

file_put_contents(self::CURRENT_DISCOVERY_STRATEGY, $strategy->value);
}

public function resolveKernel(): Kernel
{
$container = new GenericContainer();
Expand Down
24 changes: 23 additions & 1 deletion src/DiscoveryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

final class DiscoveryCache implements Cache
{
use IsCache;
use IsCache {
clear as parentClear;
}

public const string CURRENT_DISCOVERY_STRATEGY = __DIR__ . '/.cache/current_discovery_strategy';

private CacheItemPoolInterface $pool;

Expand Down Expand Up @@ -68,8 +72,26 @@ public function isValid(): bool
return $this->cacheConfig->discoveryCache->isValid();
}

public function clear(): void
{
$this->parentClear();

$this->storeStrategy(DiscoveryCacheStrategy::INVALID);
}

public function getStrategy(): DiscoveryCacheStrategy
{
return $this->cacheConfig->discoveryCache;
}

public function storeStrategy(DiscoveryCacheStrategy $strategy): void
{
$dir = dirname(self::CURRENT_DISCOVERY_STRATEGY);

if (! is_dir($dir)) {
mkdir($dir, recursive: true);
}

file_put_contents(self::CURRENT_DISCOVERY_STRATEGY, $strategy->value);
}
}

0 comments on commit 5b298b5

Please sign in to comment.