Skip to content

Commit

Permalink
Merge pull request #6 from boekkooi/expire-cleanup
Browse files Browse the repository at this point in the history
Remove the cache file when a expire item was required
  • Loading branch information
Nyholm committed Jan 24, 2016
2 parents 199382d + 4b66509 commit 97266e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/FilesystemCachePool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
17 changes: 17 additions & 0 deletions tests/FilesystemCachePoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

0 comments on commit 97266e6

Please sign in to comment.