Skip to content

Commit 219a310

Browse files
committed
[Cache] fix cleanup of expired items for PdoAdapter
1 parent 74a92a1 commit 219a310

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Adapter/PdoAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ protected function doFetch(array $ids)
195195
foreach ($expired as $id) {
196196
$stmt->bindValue(++$i, $id);
197197
}
198-
$stmt->execute($expired);
198+
$stmt->execute();
199199
}
200200
}
201201

Tests/Adapter/PdoAdapterTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,30 @@ public function createCachePool($defaultLifetime = 0)
4141
{
4242
return new PdoAdapter('sqlite:'.self::$dbFile, 'ns', $defaultLifetime);
4343
}
44+
45+
public function testCleanupExpiredItems()
46+
{
47+
$pdo = new \PDO('sqlite:'.self::$dbFile);
48+
49+
$getCacheItemCount = function () use ($pdo) {
50+
return (int) $pdo->query('SELECT COUNT(*) FROM cache_items')->fetch(\PDO::FETCH_COLUMN);
51+
};
52+
53+
$this->assertSame(0, $getCacheItemCount());
54+
55+
$cache = $this->createCachePool();
56+
57+
$item = $cache->getItem('some_nice_key');
58+
$item->expiresAfter(1);
59+
$item->set(1);
60+
61+
$cache->save($item);
62+
$this->assertSame(1, $getCacheItemCount());
63+
64+
sleep(2);
65+
66+
$newItem = $cache->getItem($item->getKey());
67+
$this->assertFalse($newItem->isHit());
68+
$this->assertSame(0, $getCacheItemCount(), 'PDOAdapter must clean up expired items');
69+
}
4470
}

0 commit comments

Comments
 (0)