Skip to content

Commit

Permalink
fix: handle corrupt files in cache (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
Crypta-Eve authored Jan 24, 2025
1 parent 53f92a0 commit 51a3da3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Cache/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ public function get(string $key, mixed $default = null): mixed
return $default;

// Get the data from the file and unserialize it
$data = unserialize(file_get_contents($cache_file_path));
$data = @unserialize(file_get_contents($cache_file_path));

if ($data === false)
return $default;

// If the cached entry is expired and does not have any ETag, remove it.
if ($data->expired() && ! $data->hasHeader('ETag')) {
// The false case occur if a cache save is incomplete so the unserialize fails.
if ($data === false || $data->expired() && ! $data->hasHeader('ETag')) {
$this->delete($key);

return $default;
Expand Down

0 comments on commit 51a3da3

Please sign in to comment.