8000 bug #29644 [Cache] fix bad optim (nicolas-grekas) · adrav/symfony@9337422 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9337422

Browse files
bug symfony#29644 [Cache] fix bad optim (nicolas-grekas)
This PR was merged into the 4.2 branch. Discussion ---------- [Cache] fix bad optim | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#29643 | License | MIT | Doc PR | - Commits ------- b76d4ea [Cache] fix bad optim
2 parents 9ade0a7 + b76d4ea commit 9337422

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function __construct(string $namespace = '', int $defaultLifetime = 0, st
3131
self::$startTime = self::$startTime ?? $_SERVER['REQUEST_TIME'] ?? time();
3232
parent::__construct('', $defaultLifetime);
3333
$this->init($namespace, $directory);
34-
35-
$e = new \Exception();
36-
$this->includeHandler = function () use ($e) { throw $e; };
34+
$this->includeHandler = static function ($type, $msg, $file, $line) {
35+
throw new \ErrorException($msg, 0, $type, $file, $line);
36+
};
3737
}
3838
}

src/Symfony/Component/Cache/Simple/PhpFilesCache.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function __construct(string $namespace = '', int $defaultLifetime = 0, st
3131
self::$startTime = self::$startTime ?? $_SERVER['REQUEST_TIME'] ?? time();
3232
parent::__construct('', $defaultLifetime);
3333
$this->init($namespace, $directory);
34-
35-
$e = new \Exception();
36-
$this->includeHandler = function () use ($e) { throw $e; };
34+
$this->includeHandler = static function ($type, $msg, $file, $line) {
35+
throw new \ErrorException($msg, 0, $type, $file, $line);
36+
};
3737
}
3838
}

src/Symfony/Component/Cache/Traits/PhpFilesTrait.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ public function prune()
5454
set_error_handler($this->includeHandler);
5555
try {
5656
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
57-
list($expiresAt) = include $file;
57+
try {
58+
list($expiresAt) = include $file;
59+
} catch (\ErrorException $e) {
60+
$expiresAt = $time;
61+
}
5862

5963
if ($time >= $expiresAt) {
6064
$pruned = $this->doUnlink($file) && !file_exists($file) && $pruned;
@@ -111,7 +115,7 @@ protected function doFetch(array $ids)
111115
if ($now >= $expiresAt) {
112116
unset($this->values[$id], $missingIds[$k]);
113117
}
114-
} catch (\Exception $e) {
118+
} catch (\ErrorException $e) {
115119
unset($missingIds[$k]);
116120
}
117121
}
@@ -137,6 +141,8 @@ protected function doHave($id)
137141
try {
138142
$file = $this->files[$id] ?? $this->files[$id] = $this->getFile($id);
139143
list($expiresAt, $value) = include $file;
144+
} catch (\ErrorException $e) {
145+
return false;
140146
} finally {
141147
restore_error_handler();
142148
}

0 commit comments

Comments
 (0)
0