[Cache] fix bad optim

This commit is contained in:
Nicolas Grekas 2018-12-18 14:39:36 +01:00
parent 64e2449f8e
commit b76d4ea95f
3 changed files with 14 additions and 8 deletions

View File

@ -31,8 +31,8 @@ class PhpFilesAdapter extends AbstractAdapter implements PruneableInterface
self::$startTime = self::$startTime ?? $_SERVER['REQUEST_TIME'] ?? time();
parent::__construct('', $defaultLifetime);
$this->init($namespace, $directory);
$e = new \Exception();
$this->includeHandler = function () use ($e) { throw $e; };
$this->includeHandler = static function ($type, $msg, $file, $line) {
throw new \ErrorException($msg, 0, $type, $file, $line);
};
}
}

View File

@ -31,8 +31,8 @@ class PhpFilesCache extends AbstractCache implements PruneableInterface
self::$startTime = self::$startTime ?? $_SERVER['REQUEST_TIME'] ?? time();
parent::__construct('', $defaultLifetime);
$this->init($namespace, $directory);
$e = new \Exception();
$this->includeHandler = function () use ($e) { throw $e; };
$this->includeHandler = static function ($type, $msg, $file, $line) {
throw new \ErrorException($msg, 0, $type, $file, $line);
};
}
}

View File

@ -54,7 +54,11 @@ trait PhpFilesTrait
set_error_handler($this->includeHandler);
try {
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
list($expiresAt) = include $file;
try {
list($expiresAt) = include $file;
} catch (\ErrorException $e) {
$expiresAt = $time;
}
if ($time >= $expiresAt) {
$pruned = $this->doUnlink($file) && !file_exists($file) && $pruned;
@ -111,7 +115,7 @@ trait PhpFilesTrait
if ($now >= $expiresAt) {
unset($this->values[$id], $missingIds[$k]);
}
} catch (\Exception $e) {
} catch (\ErrorException $e) {
unset($missingIds[$k]);
}
}
@ -137,6 +141,8 @@ trait PhpFilesTrait
try {
$file = $this->files[$id] ?? $this->files[$id] = $this->getFile($id);
list($expiresAt, $value) = include $file;
} catch (\ErrorException $e) {
return false;
} finally {
restore_error_handler();
}