mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
feat: Gzip support in ClassStorage cache
This commit is contained in:
parent
dd5c3ac241
commit
3e95ecd713
@ -3,6 +3,7 @@
|
||||
namespace Psalm\Internal\Provider;
|
||||
|
||||
use Psalm\Config;
|
||||
use Psalm\Internal\Cache;
|
||||
use Psalm\Storage\ClassLikeStorage;
|
||||
use RuntimeException;
|
||||
use UnexpectedValueException;
|
||||
@ -33,7 +34,7 @@ use const PHP_VERSION_ID;
|
||||
*/
|
||||
class ClassLikeStorageCacheProvider
|
||||
{
|
||||
private Config $config;
|
||||
private Cache $cache;
|
||||
|
||||
private string $modified_timestamps = '';
|
||||
|
||||
@ -41,7 +42,7 @@ class ClassLikeStorageCacheProvider
|
||||
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->cache = new Cache($config);
|
||||
|
||||
$storage_dir = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'Storage' . DIRECTORY_SEPARATOR;
|
||||
|
||||
@ -64,7 +65,7 @@ class ClassLikeStorageCacheProvider
|
||||
$this->modified_timestamps .= ' ' . filemtime($dependent_file_path);
|
||||
}
|
||||
|
||||
$this->modified_timestamps .= $this->config->computeHash();
|
||||
$this->modified_timestamps .= $config->computeHash();
|
||||
}
|
||||
|
||||
public function writeToCache(ClassLikeStorage $storage, string $file_path, string $file_contents): void
|
||||
@ -80,11 +81,7 @@ class ClassLikeStorageCacheProvider
|
||||
}
|
||||
|
||||
$cache_location = $this->getCacheLocationForClass($fq_classlike_name_lc, $file_path, true);
|
||||
if ($this->config->use_igbinary) {
|
||||
file_put_contents($cache_location, igbinary_serialize($storage), LOCK_EX);
|
||||
} else {
|
||||
file_put_contents($cache_location, serialize($storage), LOCK_EX);
|
||||
}
|
||||
$this->cache->saveItem($cache_location, $storage);
|
||||
}
|
||||
|
||||
public function getLatestFromCache(
|
||||
@ -123,26 +120,9 @@ class ClassLikeStorageCacheProvider
|
||||
*/
|
||||
private function loadFromCache(string $fq_classlike_name_lc, ?string $file_path): ?ClassLikeStorage
|
||||
{
|
||||
$cache_location = $this->getCacheLocationForClass($fq_classlike_name_lc, $file_path);
|
||||
|
||||
if (file_exists($cache_location)) {
|
||||
if ($this->config->use_igbinary) {
|
||||
$storage = igbinary_unserialize(Providers::safeFileGetContents($cache_location));
|
||||
|
||||
if ($storage instanceof ClassLikeStorage) {
|
||||
return $storage;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$storage = unserialize(Providers::safeFileGetContents($cache_location));
|
||||
|
||||
if ($storage instanceof ClassLikeStorage) {
|
||||
return $storage;
|
||||
}
|
||||
|
||||
return null;
|
||||
$storage = $this->cache->getItem($this->getCacheLocationForClass($fq_classlike_name_lc, $file_path));
|
||||
if ($storage instanceof ClassLikeStorage) {
|
||||
return $storage;
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -153,7 +133,7 @@ class ClassLikeStorageCacheProvider
|
||||
?string $file_path,
|
||||
bool $create_directory = false
|
||||
): string {
|
||||
$root_cache_directory = $this->config->getCacheDirectory();
|
||||
$root_cache_directory = $this->cache->getCacheDirectory();
|
||||
|
||||
if (!$root_cache_directory) {
|
||||
throw new UnexpectedValueException('No cache directory defined');
|
||||
@ -186,6 +166,6 @@ class ClassLikeStorageCacheProvider
|
||||
return $parser_cache_directory
|
||||
. DIRECTORY_SEPARATOR
|
||||
. $file_path_sha
|
||||
. ($this->config->use_igbinary ? '-igbinary' : '');
|
||||
. ($this->cache->use_igbinary ? '-igbinary' : '');
|
||||
}
|
||||
}
|
||||
|
@ -112,9 +112,9 @@ class FileStorageCacheProvider
|
||||
*/
|
||||
private function loadFromCache(string $file_path): ?FileStorage
|
||||
{
|
||||
$cache = $this->cache->getItem($this->getCacheLocationForPath($file_path));
|
||||
if ($cache instanceof FileStorage) {
|
||||
return $cache;
|
||||
$storage = $this->cache->getItem($this->getCacheLocationForPath($file_path));
|
||||
if ($storage instanceof FileStorage) {
|
||||
return $storage;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user