Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6fd9516

Browse filesBrowse files
committed
[Cache] fix cleanup of expired items for PdoAdapter
1 parent 25ab339 commit 6fd9516
Copy full SHA for 6fd9516

File tree

2 files changed

+30
-4
lines changed
Filter options

2 files changed

+30
-4
lines changed

‎src/Symfony/Component/Cache/Adapter/PdoAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/PdoAdapter.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class PdoAdapter extends AbstractAdapter
5656
* @param int $defaultLifetime
5757
* @param array $options An associative array of options
5858
*
59-
* @throws InvalidArgumentException When first argument is not PDO nor Connection nor string
60-
* @throws InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
61-
* @throws InvalidArgumentException When namespace contains invalid characters
59+
* @throws \InvalidArgumentException When first argument is not PDO nor Connection nor string
60+
* @throws \InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
61+
* @throws \InvalidArgumentException When namespace contains invalid characters
6262
*/
6363
public function __construct($connOrDsn, $namespace = '', $defaultLifetime = 0, array $options = array())
6464
{
@@ -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

‎src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php
+26Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.