test: verify touch refreshes stale entries

This commit is contained in:
Torsten Dittmann committed 2026-05-08 16:45:22 +04:00
1 parent c6293e25f0
commit bef0ec00c4
2 files changed
+4 -17

No files matched your search

+4 -1
View File
@@ -62,8 +62,11 @@ abstract class Base extends TestCase
$result = self::$cache->save('touch-key', 'touch data', 'touch-key');
$this->assertEquals('touch data', $result);
sleep(2);
$this->assertEquals(false, self::$cache->load('touch-key', 1, 'touch-key'));
$this->assertEquals(true, self::$cache->touch('touch-key', 'touch-key'));
$this->assertEquals('touch data', self::$cache->load('touch-key', 60, 'touch-key'));
$this->assertEquals('touch data', self::$cache->load('touch-key', 1, 'touch-key'));
$this->assertEquals(false, self::$cache->touch('missing-touch-key', 'missing-touch-key'));
self::$cache->purge('touch-key');
-16
View File
@@ -20,20 +20,4 @@ class MemoryTest extends Base
self::$cache->save('test:file36', 'file36');
$this->assertEquals(4, self::$cache->getSize());
}
public function testTouchExpiredEntry(): void
{
$adapter = new Memory();
$cache = new Cache($adapter);
$cache->save('expired-touch-key', 'expired data');
/** @var array{time: int, data: string} $stored */
$stored = $adapter->store['expired-touch-key'];
$stored['time'] = time() - 10;
$adapter->store['expired-touch-key'] = $stored;
$this->assertEquals(false, $cache->load('expired-touch-key', 1));
$this->assertEquals(true, $cache->touch('expired-touch-key'));
$this->assertEquals('expired data', $cache->load('expired-touch-key', 1));
}
}