Skip to content

Commit ff0de67

Browse files
[Cache] more granular handling of exceptions in AbstractTrait::clear()
1 parent b61c8fc commit ff0de67

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,26 @@ public function hasItem($key)
105105
public function clear()
106106
{
107107
$this->deferred = array();
108-
try {
109-
if ($cleared = $this->versioningIsEnabled) {
110-
$namespaceVersion = 2;
111-
try {
112-
foreach ($this->doFetch(array('@'.$this->namespace)) as $v) {
113-
$namespaceVersion = 1 + (int) $v;
114-
}
115-
} catch (\Exception $e) {
108+
if ($cleared = $this->versioningIsEnabled) {
109+
$namespaceVersion = 2;
110+
try {
111+
foreach ($this->doFetch(array('@'.$this->namespace)) as $v) {
112+
$namespaceVersion = 1 + (int) $v;
116113
}
117-
$namespaceVersion .= ':';
114+
} catch (\Exception $e) {
115+
}
116+
$namespaceVersion .= ':';
117+
try {
118118
$cleared = $this->doSave(array('@'.$this->namespace => $namespaceVersion), 0);
119-
if ($cleared = true === $cleared || array() === $cleared) {
120-
$this->namespaceVersion = $namespaceVersion;
121-
}
119+
} catch (\Exception $e) {
120+
$cleared = false;
121+
}
122+
if ($cleared = true === $cleared || array() === $cleared) {
123+
$this->namespaceVersion = $namespaceVersion;
122124
}
125+
}
123126

127+
try {
124128
return $this->doClear($this->namespace) || $cleared;
125129
} catch (\Exception $e) {
126130
CacheItem::log($this->logger, 'Failed to clear the cache', array('exception' => $e));

0 commit comments

Comments
 (0)