bug #23326 [Cache] fix cleanup of expired items for PdoAdapter (dmaicher)

This PR was merged into the 3.2 branch.

Discussion
----------

[Cache] fix cleanup of expired items for PdoAdapter

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | https://github.com/symfony/symfony/issues/23313
| License       | MIT
| Doc PR        | -

This fixes the query being executed to cleanup expired items from the `cache_items` table using the `PdoAdapter`.

I also added a test case to make sure we do the cleanup successfully.

Commits
-------

c183b0e06d [Cache] fix cleanup of expired items for PdoAdapter
This commit is contained in:
Fabien Potencier 2017-07-03 08:43:08 +03:00
commit 07c38df9e9
2 changed files with 27 additions and 1 deletions

View File

@ -195,7 +195,7 @@ class PdoAdapter extends AbstractAdapter
foreach ($expired as $id) {
$stmt->bindValue(++$i, $id);
}
$stmt->execute($expired);
$stmt->execute();
}
}

View File

@ -41,4 +41,30 @@ class PdoAdapterTest extends AdapterTestCase
{
return new PdoAdapter('sqlite:'.self::$dbFile, 'ns', $defaultLifetime);
}
public function testCleanupExpiredItems()
{
$pdo = new \PDO('sqlite:'.self::$dbFile);
$getCacheItemCount = function () use ($pdo) {
return (int) $pdo->query('SELECT COUNT(*) FROM cache_items')->fetch(\PDO::FETCH_COLUMN);
};
$this->assertSame(0, $getCacheItemCount());
$cache = $this->createCachePool();
$item = $cache->getItem('some_nice_key');
$item->expiresAfter(1);
$item->set(1);
$cache->save($item);
$this->assertSame(1, $getCacheItemCount());
sleep(2);
$newItem = $cache->getItem($item->getKey());
$this->assertFalse($newItem->isHit());
$this->assertSame(0, $getCacheItemCount(), 'PDOAdapter must clean up expired items');
}
}