Skip to content

Commit 51a3da3

Browse files
authored
fix: handle corrupt files in cache (#100)
1 parent 53f92a0 commit 51a3da3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Cache/FileCache.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,14 @@ public function get(string $key, mixed $default = null): mixed
142142
return $default;
143143

144144
// Get the data from the file and unserialize it
145-
$data = unserialize(file_get_contents($cache_file_path));
145+
$data = @unserialize(file_get_contents($cache_file_path));
146146

147147
if ($data === false)
148148
return $default;
149149

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

154155
return $default;

0 commit comments

Comments
 (0)