mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Bust cache when config changes, don’t rely on > modified time
This commit is contained in:
parent
f017599b3f
commit
df8b0a1fc5
@ -297,9 +297,9 @@ class Config
|
||||
public $exit_functions = [];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @var string
|
||||
*/
|
||||
public $modified_time = 0;
|
||||
public $hash = '';
|
||||
|
||||
/** @var string|null */
|
||||
public $error_baseline = null;
|
||||
@ -388,7 +388,7 @@ class Config
|
||||
|
||||
try {
|
||||
$config = self::loadFromXML($base_dir, $file_contents);
|
||||
$config->modified_time = filemtime($file_path);
|
||||
$config->hash = sha1($file_contents);
|
||||
} catch (ConfigException $e) {
|
||||
throw new ConfigException(
|
||||
'Problem parsing ' . $file_path . ":\n" . ' ' . $e->getMessage()
|
||||
|
@ -43,7 +43,7 @@ class ClassLikeStorageCacheProvider
|
||||
$this->modified_timestamps .= ' ' . filemtime($dependent_file_path);
|
||||
}
|
||||
|
||||
$this->modified_timestamps .= PSALM_VERSION . $this->config->modified_time;
|
||||
$this->modified_timestamps .= PSALM_VERSION . $this->config->hash;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,15 +34,23 @@ class FileReferenceCacheProvider
|
||||
const CLASS_METHOD_CACHE_NAME = 'class_method_references';
|
||||
const ISSUES_CACHE_NAME = 'issues';
|
||||
const FILE_MAPS_CACHE_NAME = 'file_maps';
|
||||
const CONFIG_HASH_CACHE_NAME = 'config';
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $config_changed;
|
||||
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->config_changed = $config->hash !== $this->getConfigHashCache();
|
||||
$this->setConfigHashCache($config->hash);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -191,7 +199,7 @@ class FileReferenceCacheProvider
|
||||
|
||||
if ($cache_directory
|
||||
&& file_exists($correct_methods_cache_location)
|
||||
&& filemtime($correct_methods_cache_location) > $this->config->modified_time
|
||||
&& !$this->config_changed
|
||||
) {
|
||||
/** @var array<string, array<string, int>> */
|
||||
return unserialize(file_get_contents($correct_methods_cache_location));
|
||||
@ -229,7 +237,7 @@ class FileReferenceCacheProvider
|
||||
|
||||
if ($cache_directory
|
||||
&& file_exists($file_maps_cache_location)
|
||||
&& filemtime($file_maps_cache_location) > $this->config->modified_time
|
||||
&& !$this->config_changed
|
||||
) {
|
||||
/** @var array<string, array{0: TaggedCodeType, 1: TaggedCodeType}> */
|
||||
$file_maps_cache = unserialize(file_get_contents($file_maps_cache_location));
|
||||
@ -256,4 +264,41 @@ class FileReferenceCacheProvider
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|false
|
||||
*/
|
||||
public function getConfigHashCache()
|
||||
{
|
||||
$cache_directory = $this->config->getCacheDirectory();
|
||||
|
||||
$config_hash_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::CONFIG_HASH_CACHE_NAME;
|
||||
|
||||
if ($cache_directory
|
||||
&& file_exists($config_hash_cache_location)
|
||||
) {
|
||||
/** @var string */
|
||||
$file_maps_cache = unserialize(file_get_contents($config_hash_cache_location));
|
||||
return $file_maps_cache;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setConfigHashCache(string $hash)
|
||||
{
|
||||
$cache_directory = Config::getInstance()->getCacheDirectory();
|
||||
|
||||
if ($cache_directory) {
|
||||
$config_hash_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::CONFIG_HASH_CACHE_NAME;
|
||||
|
||||
file_put_contents(
|
||||
$config_hash_cache_location,
|
||||
serialize($hash)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class FileStorageCacheProvider
|
||||
$this->modified_timestamps .= ' ' . filemtime($dependent_file_path);
|
||||
}
|
||||
|
||||
$this->modified_timestamps .= PSALM_VERSION . $this->config->modified_time;
|
||||
$this->modified_timestamps .= PSALM_VERSION . $this->config->hash;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user