8000 simplify prune implementation · symfony/symfony@17fce58 · GitHub
[go: up one dir, main page]

Skip to content

Commit 17fce58

Browse files
committed
simplify prune implementation
1 parent 78d31e1 commit 17fce58

File tree

4 files changed

+21
-69
lines changed

4 files changed

+21
-69
lines changed

src/Symfony/Component/Cache/Adapter/ChainAdapter.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Symfony\Component\Cache\CacheItem;
1717
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1818
use Symfony\Component\Cache\PruneableInterface;
19-
use Symfony\Component\Cache\Traits\ChainTrait;
2019

2120
/**
2221
* Chains several adapters together.
@@ -28,8 +27,6 @@
2827
*/
2928
class ChainAdapter implements AdapterInterface, PruneableInterface
3029
{
31-
use ChainTrait;
32-
3330
private $adapters = array();
3431
private $adapterCount;
3532
private $saveUp;
@@ -241,6 +238,14 @@ public function commit()
241238
*/
242239
public function prune()
243240
{
244-
return $this->doPrune($this->adapters);
241+
$pruned = true;
242+
243+
foreach ($this->adapters as $adapter) {
244+
if ($adapter instanceof PruneableInterface) {
245+
$pruned = $adapter->prune() && $pruned;
246+
}
247+
}
248+
249+
return $pruned;
245250
}< 8000 /div>
246251
}

src/Symfony/Component/Cache/Simple/ChainCache.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Psr\SimpleCache\CacheInterface;
1515
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1616
use Symfony\Component\Cache\PruneableInterface;
17-
use Symfony\Component\Cache\Traits\ChainTrait;
1817

1918
/**
2019
* Chains several caches together.
@@ -26,8 +25,6 @@
2625
*/
2726
class ChainCache implements CacheInterface, PruneableInterface
2827
{
29-
use ChainTrait;
30-
3128
private $miss;
3229
private $caches = array();
3330
private $defaultLifetime;
@@ -229,6 +226,14 @@ public function setMultiple($values, $ttl = null)
229226
*/
230227
public function prune()
231228
{
232-
return $this->doPrune($this->caches);
229+
$pruned = true;
230+
231+
foreach ($this->caches as $cache) {
232+
if ($cache instanceof PruneableInterface) {
233+
$pruned = $cache->prune() && $pruned;
234+
}
235+
}
236+
237+
return $pruned;
233238
}
234239
}

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

Lines changed: 0 additions & 42 deletions
This file was deleted.

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,10 @@ public function createTable()
142142
*/
143143
public function prune()
144144
{
145-
$pdoConn = $this->getConnection();
146-
$selects = $pdoConn->prepare("SELECT $this->idCol FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time");
147-
$selects->bindValue(':time', time(), \PDO::PARAM_INT);
148-
$selects->execute();
145+
$deletes = $this->getConnection()->prepare("DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time");
146+
$deletes->bindValue(':time', time(), \Pdo::PARAM_INT);
149147

150-
if (0 === count($expired = $selects->fetchAll(\PDO::FETCH_COLUMN))) {
151-
return true;
152-
}
153-
154-
$anchors = array_map(function ($i) {
155-
return sprintf(':id_%d_anchor', $i);
156-
}, array_keys($expired));
157-
158-
$deletes = $pdoConn->prepare(sprintf("DELETE FROM $this->table WHERE $this->idCol IN (%s)", implode(',', $anchors)));
159-
160-
foreach ($anchors as $i => $a) {
161-
$deletes->bindValue($a, $expired[$i], \PDO::PARAM_STR);
162-
}
163-
164-
return $deletes->execute() && $deletes->rowCount() === count($expired);
148+
return $deletes->execute();
165149
}
166150

167151
/**

0 commit comments

Comments
 (0)
0