diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index 91afb212e0e4..c67b2180a643 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -285,35 +285,13 @@ public function getMetaData(string $key) { $key = static::validateKey($key, $this->prefix); - if (! is_file($this->path . $key)) + if (false === $data = $this->getItem($key)) { return false; // This will return null in a future release } - $data = @unserialize(file_get_contents($this->path . $key)); - - if (! is_array($data) || ! isset($data['ttl'])) - { - return false; // This will return null in a future release - } - - // Consider expired items as missing - $expire = $data['time'] + $data['ttl']; - - // @phpstan-ignore-next-line - if ($data['ttl'] > 0 && time() > $expire) - { - // If the file is still there then remove it - if (is_file($this->path . $key)) - { - unlink($this->path . $key); - } - - return false; // This will return null in a future release - } - return [ - 'expire' => $expire, + 'expire' => $data['time'] + $data['ttl'], 'mtime' => filemtime($this->path . $key), 'data' => $data['data'], ]; @@ -348,15 +326,19 @@ protected function getItem(string $filename) return false; } - $data = unserialize(file_get_contents($this->path . $filename)); + $data = @unserialize(file_get_contents($this->path . $filename)); + if (! is_array($data) || ! isset($data['ttl'])) + { + return false; + } // @phpstan-ignore-next-line if ($data['ttl'] > 0 && time() > $data['time'] + $data['ttl']) { - // If the file is still there then remove it + // If the file is still there then try to remove it if (is_file($this->path . $filename)) { - unlink($this->path . $filename); + @unlink($this->path . $filename); } return false;