Skip to content

Commit

Permalink
misc consistency improvements for cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Jun 27, 2023
1 parent 0584339 commit b877aa7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/Psalm/Codebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,12 @@ public function createClassLikeStorage(string $fq_classlike_name): ClassLikeStor

public function cacheClassLikeStorage(ClassLikeStorage $classlike_storage, string $file_path): void
{
$file_contents = $this->file_provider->getContents($file_path);

if ($this->classlike_storage_provider->cache) {
$this->classlike_storage_provider->cache->writeToCache($classlike_storage, $file_path, $file_contents);
if (!$this->classlike_storage_provider->cache) {
return;
}

$file_contents = $this->file_provider->getContents($file_path);
$this->classlike_storage_provider->cache->writeToCache($classlike_storage, $file_path, $file_contents);
}

public function exhumeClassLikeStorage(string $fq_classlike_name, string $file_path): void
Expand Down
3 changes: 2 additions & 1 deletion src/Psalm/Internal/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use function gzinflate;
use function igbinary_serialize;
use function igbinary_unserialize;
use function is_writable;
use function lz4_compress;
use function lz4_uncompress;
use function serialize;
Expand Down Expand Up @@ -86,7 +87,7 @@ public function getItem(string $path)

public function deleteItem(string $path): void
{
if (file_exists($path)) {
if (@is_writable($path)) {
@unlink($path);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use function is_null;
use function mkdir;
use function strtolower;
use function unlink;

use const DIRECTORY_SEPARATOR;
use const PHP_VERSION_ID;
Expand Down Expand Up @@ -95,7 +94,7 @@ public function getLatestFromCache(
if (@get_class($cached_value) === '__PHP_Incomplete_Class'
|| $cache_hash !== $cached_value->hash
) {
unlink($this->getCacheLocationForClass($fq_classlike_name_lc, $file_path));
$this->cache->deleteItem($this->getCacheLocationForClass($fq_classlike_name_lc, $file_path));

throw new UnexpectedValueException($fq_classlike_name_lc . ' should not be outdated');
}
Expand Down
6 changes: 2 additions & 4 deletions src/Psalm/Internal/Provider/ParserCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
use function is_dir;
use function is_readable;
use function is_string;
use function is_writable;
use function json_decode;
use function json_encode;
use function mkdir;
use function scandir;
use function touch;
use function unlink;

use const DIRECTORY_SEPARATOR;
use const JSON_THROW_ON_ERROR;
Expand Down Expand Up @@ -319,8 +317,8 @@ public function deleteOldParserCaches(float $time_before): int
continue;
}

if (filemtime($full_path) < $time_before && is_writable($full_path)) {
unlink($full_path);
if (filemtime($full_path) < $time_before) {
$this->cache->deleteItem($full_path);
++$removed_count;
}
}
Expand Down

0 comments on commit b877aa7

Please sign in to comment.