|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * A simple, unified cache handler (last modified: 2026.03.20). |
| 3 | + * A simple, unified cache handler (last modified: 2026.03.22). |
4 | 4 | * |
5 | 5 | * This file is a part of the "common classes package", utilised by a number of |
6 | 6 | * packages and projects, including CIDRAM and phpMussel. |
@@ -144,7 +144,7 @@ class Cache extends CommonAbstract implements \ArrayAccess, \Countable |
144 | 144 | /** |
145 | 145 | * @var string Prepared get query for PDO. |
146 | 146 | */ |
147 | | - public const GET_QUERY = 'SELECT `Data` FROM `Cache` WHERE `Key` = :key LIMIT 1'; |
| 147 | + public const GET_QUERY = 'SELECT * FROM `Cache` WHERE `Key` = :key LIMIT 1'; |
148 | 148 |
|
149 | 149 | /** |
150 | 150 | * @var string Prepared delete query for PDO. |
@@ -460,11 +460,14 @@ public function getEntry(string $Entry) |
460 | 460 | return $this->unserializeEntry($this->WorkingData->get($Entry)); |
461 | 461 | } |
462 | 462 | if ($this->Using === 'PDO') { |
463 | | - $this->clearExpiredPDO(); |
464 | 463 | $PDO = $this->WorkingData->prepare(self::GET_QUERY); |
465 | 464 | if ($PDO !== false && $PDO->execute([':key' => $Entry])) { |
466 | 465 | $Data = $PDO->fetch(\PDO::FETCH_ASSOC); |
467 | | - if (!isset($Data['Data'])) { |
| 466 | + if (!isset($Data['Data'], $Data['Time'])) { |
| 467 | + return false; |
| 468 | + } |
| 469 | + if ($Data['Time'] > 0 && $Data['Time'] < \time()) { |
| 470 | + $this->clearExpiredPDO(); |
468 | 471 | return false; |
469 | 472 | } |
470 | 473 | if (\substr($Data['Data'], 0, 3) === 'gz:') { |
@@ -1397,7 +1400,7 @@ public function offsetExists($Offset): bool |
1397 | 1400 | $PDO = $this->WorkingData->prepare(self::GET_QUERY); |
1398 | 1401 | if ($PDO !== false && $PDO->execute([':key' => $Entry])) { |
1399 | 1402 | $Data = $PDO->fetch(\PDO::FETCH_ASSOC); |
1400 | | - return isset($Data['Data']); |
| 1403 | + return isset($Data['Data'], $Data['Time']) && !($Data['Time'] > 0 && $Data['Time'] < \time()); |
1401 | 1404 | } |
1402 | 1405 | return false; |
1403 | 1406 | } |
|
0 commit comments