Skip to content

Commit

Permalink
check if file in cache already before adding
Browse files Browse the repository at this point in the history
* reduces I/O by 30%
* minimal performance improvement (<0.5%)
  • Loading branch information
kkmuffme committed Jun 28, 2022
1 parent b200889 commit 02fe7f8
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 02fe7f8

Please sign in to comment.