function ComposerInspector::invalidateCacheIfNeeded
Invalidates cached data if composer.json or composer.lock have changed.
The following cached data may be invalidated:
- Installed package lists (see ::getInstalledPackageList()).
Parameters
string $working_dir: A directory that contains a `composer.json` file, and optionally a `composer.lock`. If either file has changed since the last time this method was called, any cached data for the directory will be invalidated.
Return value
bool TRUE if the cached data was invalidated, otherwise FALSE.
1 call to ComposerInspector::invalidateCacheIfNeeded()
- ComposerInspector::validateProject in core/
modules/ package_manager/ src/ ComposerInspector.php - Checks that `composer.json` is valid and `composer.lock` exists.
File
-
core/
modules/ package_manager/ src/ ComposerInspector.php, line 437
Class
- ComposerInspector
- Defines a class to get information from Composer.
Namespace
Drupal\package_managerCode
private function invalidateCacheIfNeeded(string $working_dir) : bool {
static $known_hashes = [];
$invalidate = FALSE;
foreach ([
'composer.json',
'composer.lock',
] as $filename) {
$known_hash = $known_hashes[$working_dir][$filename] ?? '';
// If the file doesn't exist, hash_file() will return FALSE.
$current_hash = @hash_file('xxh64', $working_dir . DIRECTORY_SEPARATOR . $filename);
if ($known_hash && $current_hash && hash_equals($known_hash, $current_hash)) {
continue;
}
$known_hashes[$working_dir][$filename] = $current_hash;
$invalidate = TRUE;
}
if ($invalidate) {
unset($this->packageLists[$working_dir]);
}
return $invalidate;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.