8000 Use 0 for unlimited expiry · symfony/symfony@b4259a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b4259a6

Browse files
committed
Use 0 for unlimited expiry
1 parent 05a0452 commit b4259a6

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public function prune()
3636
continue;
3737
}
3838

39-
if ($time >= (int) $expiresAt = fgets($h)) {
39+
if (($expiresAt = (int) fgets($h)) && $time >= $expiresAt) {
4040
fclose($h);
41-
$pruned = isset($expiresAt[0]) && @unlink($file) && !file_exists($file) && $pruned;
41+
$pruned = @unlink($file) && !file_exists($file) && $pruned;
4242
} else {
4343
fclose($h);
4444
}
@@ -60,11 +60,9 @@ protected function doFetch(array $ids)
6060
if (!file_exists($file) || !$h = @fopen($file, 'rb')) {
6161
continue;
6262
}
63-
if ($now >= (int) $expiresAt = fgets($h)) {
63+
if (($expiresAt = (int) fgets($h)) && $now >= $expiresAt) {
6464
fclose($h);
65-
if (isset($expiresAt[0])) {
66-
@unlink($file);
67-
}
65+
@unlink($file);
6866
} else {
6967
$i = rawurldecode(rtrim(fgets($h)));
7068
$value = stream_get_contents($h);
@@ -94,7 +92,7 @@ protected function doHave($id)
9492
protected function doSave(array $values, $lifetime)
9593
{
9694
$ok = true;
97-
$expiresAt = time() + ($lifetime ?: 31557600); // 31557600s = 1 year
95+
$expiresAt = $lifetime ? (time() + $lifetime) : 0;
9896

9997
foreach ($values as $id => $value) {
10098
$ok = $this->write($this->getFile($id, true), $expiresAt."\n".rawurlencode($id)."\n".serialize($value), $expiresAt) && $ok;

0 commit comments

Comments
 (0)
0