Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve cache flush debug info and code if cache disabled #8707

Merged
merged 2 commits into from Nov 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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