Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d0e016

Browse files
committed
prune pdo using namespace if set
1 parent 87ac9a6 commit 5d0e016

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Symfony/Component/Cache/Traits/PdoTrait.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ trait PdoTrait
3434
private $username = '';
3535
private $password = '';
3636
private $connectionOptions = array();
37+
private $namespace;
3738

3839
private function init($connOrDsn, $namespace, $defaultLifetime, array $options)
3940
{
@@ -63,6 +64,7 @@ private function init($connOrDsn, $namespace, $defaultLifetime, array $options)
6364
$this->username = isset($options['db_username']) ? $options['db_username'] : $this->username;
6465
$this->password = isset($options['db_password']) ? $options['db_password'] : $this->password;
6566
$this->connectionOptions = isset($options['db_connection_options']) ? $options['db_connection_options'] : $this->connectionOptions;
67+
$this->namespace = $namespace;
6668

6769
parent::__construct($namespace, $defaultLifetime);
6870
}
@@ -142,10 +144,20 @@ public function createTable()
142144
*/
143145
public function prune()
144146
{
145-
$deletes = $this->getConnection()->prepare("DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time");
146-
$deletes->bindValue(':time', time(), \Pdo::PARAM_INT);
147+
$deleteSql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time";
147148

148-
return $deletes->execute();
149+
if ($this->namespace) {
150+
$deleteSql .= " AND $this->idCol LIKE :namespace";
151+
}
152+
153+
$delete = $this->getConnection()->prepare($deleteSql);
154+
$delete->bindValue(':time', time(), \PDO::PARAM_INT);
155+
156+
if ($this->namespace) {
157+
$delete->bindValue(':namespace', sprintf('%s%%', $this->namespace), \PDO::PARAM_STR);
158+
}
159+
160+
return $delete->execute();
149161
}
150162

151163
/**

0 commit comments

Comments
 (0)