diff --git a/src/FilesystemCachePool.php b/src/FilesystemCachePool.php index 5d576b9..b20bd7a 100644 --- a/src/FilesystemCachePool.php +++ b/src/FilesystemCachePool.php @@ -46,6 +46,8 @@ protected function fetchObjectFromCache($key) $data = unserialize($this->filesystem->read($file)); if ($data[0] !== null && time() > $data[0]) { + $this->clearOneObjectFromCache($key); + return [false, null]; } diff --git a/tests/FilesystemCachePoolTest.php b/tests/FilesystemCachePoolTest.php index a3c77af..747303d 100644 --- a/tests/FilesystemCachePoolTest.php +++ b/tests/FilesystemCachePoolTest.php @@ -27,4 +27,21 @@ public function testInvalidKey() $pool->getItem('test%string')->get(); } + + public function testCleanupOnExpire() + { + $pool = $this->createCachePool(); + + $item = $pool->getItem('test_ttl_null'); + $item->set('data'); + $item->expiresAt(new \DateTime('now')); + $pool->save($item); + $this->assertTrue($this->getFilesystem()->has('cache/test_ttl_null')); + + sleep(1); + + $item = $pool->getItem('test_ttl_null'); + $this->assertFalse($item->isHit()); + $this->assertFalse($this->getFilesystem()->has('cache/test_ttl_null')); + } }