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 07c38df

Browse filesBrowse files
committed
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 | #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 ------- c183b0e [Cache] fix cleanup of expired items for PdoAdapter
2 parents 25ab339 + c183b0e commit 07c38df
Copy full SHA for 07c38df

File tree

2 files changed

+27
-1
lines changed
Filter options

2 files changed

+27
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/PdoAdapter.php
+1-1Lines 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

‎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.