Skip to content

[Cache] Fix order of writes in ChainAdapter #21166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions src/Symfony/Component/Cache/Adapter/ChainAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
class ChainAdapter implements AdapterInterface
{
private $adapters = array();
private $adapterCount;
private $saveUp;

/**
Expand All @@ -50,6 +51,7 @@ public function __construct(array $adapters, $maxLifetime = 0)
$this->adapters[] = new ProxyAdapter($adapter);
}
}
$this->adapterCount = count($this->adapters);

$this->saveUp = \Closure::bind(
function ($adapter, $item) use ($maxLifetime) {
Expand Down Expand Up @@ -146,9 +148,10 @@ public function hasItem($key)
public function clear()
{
$cleared = true;
$i = $this->adapterCount;

foreach ($this->adapters as $adapter) {
$cleared = $adapter->clear() && $cleared;
while ($i--) {
$cleared = $this->adapters[$i]->clear() && $cleared;
}

return $cleared;
Expand All @@ -160,9 +163,10 @@ public function clear()
public function deleteItem($key)
{
$deleted = true;
$i = $this->adapterCount;

foreach ($this->adapters as $adapter) {
$deleted = $adapter->deleteItem($key) && $deleted;
while ($i--) {
$deleted = $this->adapters[$i]->deleteItem($key) && $deleted;
}

return $deleted;
Expand All @@ -174,9 +178,10 @@ public function deleteItem($key)
public function deleteItems(array $keys)
{
$deleted = true;
$i = $this->adapterCount;

foreach ($this->adapters as $adapter) {
$deleted = $adapter->deleteItems($keys) && $deleted;
while ($i--) {
$deleted = $this->adapters[$i]->deleteItems($keys) && $deleted;
}

return $deleted;
Expand All @@ -188,9 +193,10 @@ public function deleteItems(array $keys)
public function save(CacheItemInterface $item)
{
$saved = true;
$i = $this->adapterCount;

foreach ($this->adapters as $adapter) {
$saved = $adapter->save($item) && $saved;
while ($i--) {
$saved = $this->adapters[$i]->save($item) && $saved;
}

return $saved;
Expand All @@ -202,9 +208,10 @@ public function save(CacheItemInterface $item)
public function saveDeferred(CacheItemInterface $item)
{
$saved = true;
$i = $this->adapterCount;

foreach ($this->adapters as $adapter) {
$saved = $adapter->saveDeferred($item) && $saved;
while ($i--) {
$saved = $this->adapters[$i]->saveDeferred($item) && $saved;
}

return $saved;
Expand All @@ -216,9 +223,10 @@ public function saveDeferred(CacheItemInterface $item)
public function commit()
{
$committed = true;
$i = $this->adapterCount;

foreach ($this->adapters as $adapter) {
$committed = $adapter->commit() && $committed;
while ($i--) {
$committed = $this->adapters[$i]->commit() && $committed;
}

return $committed;
Expand Down