From 90586083e66e7bda677e6c7d350dd26e6602beec Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Tue, 28 Jun 2022 20:46:23 +0200 Subject: [PATCH] check if file in cache already before adding * reduces I/O by 30% * minimal performance improvement (<0.5%) --- .../Internal/Provider/ClassLikeStorageCacheProvider.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php b/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php index 9581702f0ed..dae227f5520 100644 --- a/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php +++ b/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php @@ -17,6 +17,7 @@ use function igbinary_serialize; use function igbinary_unserialize; use function is_dir; +use function is_null; use function mkdir; use function serialize; use function strtolower; @@ -75,9 +76,15 @@ public function writeToCache(ClassLikeStorage $storage, string $file_path, strin { $fq_classlike_name_lc = strtolower($storage->name); - $cache_location = $this->getCacheLocationForClass($fq_classlike_name_lc, $file_path, true); $storage->hash = $this->getCacheHash($file_path, $file_contents); + // check if we have it in cache already + $cached_value = $this->loadFromCache($fq_classlike_name_lc, $file_path); + if (!is_null($cached_value) && $cached_value->hash === $storage->hash) { + return; + } + + $cache_location = $this->getCacheLocationForClass($fq_classlike_name_lc, $file_path, true); if ($this->config->use_igbinary) { file_put_contents($cache_location, igbinary_serialize($storage)); } else {