Skip to content

Commit

Permalink
Merge pull request #8707 from kkmuffme/improve-cache-flush-debug-info
Browse files Browse the repository at this point in the history
improve cache flush debug info and code if cache disabled
  • Loading branch information
orklah committed Nov 18, 2022
2 parents 48c0df6 + 17c246b commit 4a83f88
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Expand Up @@ -64,6 +64,7 @@
use function array_map;
use function array_merge;
use function array_shift;
use function clearstatcache;
use function cli_set_process_title;
use function count;
use function defined;
Expand Down Expand Up @@ -348,15 +349,22 @@ public function __construct(

private function clearCacheDirectoryIfConfigOrComposerLockfileChanged(): void
{
$cache_directory = $this->config->getCacheDirectory();
if ($cache_directory === null) {
return;
}

if ($this->project_cache_provider
&& $this->project_cache_provider->hasLockfileChanged()
) {
$this->progress->debug(
'Composer lockfile change detected, clearing cache' . "\n"
);
// we only clear the cache if it actually exists
// if it's not populated yet, we don't clear anything but populate the cache instead
clearstatcache(true, $cache_directory);
if (is_dir($cache_directory)) {
$this->progress->debug(
'Composer lockfile change detected, clearing cache directory ' . $cache_directory . "\n"
);

$cache_directory = $this->config->getCacheDirectory();
if ($cache_directory !== null) {
Config::removeCacheDirectory($cache_directory);
}

Expand All @@ -368,12 +376,12 @@ private function clearCacheDirectoryIfConfigOrComposerLockfileChanged(): void
} elseif ($this->file_reference_provider->cache
&& $this->file_reference_provider->cache->hasConfigChanged()
) {
$this->progress->debug(
'Config change detected, clearing cache' . "\n"
);
clearstatcache(true, $cache_directory);
if (is_dir($cache_directory)) {
$this->progress->debug(
'Config change detected, clearing cache directory ' . $cache_directory . "\n"
);

$cache_directory = $this->config->getCacheDirectory();
if ($cache_directory !== null) {
Config::removeCacheDirectory($cache_directory);
}

Expand Down

0 comments on commit 4a83f88

Please sign in to comment.