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 d1b6793

Browse filesBrowse files
committed
[Cache] Add missing log
1 parent 4145222 commit d1b6793
Copy full SHA for d1b6793

File tree

Expand file treeCollapse file tree

1 file changed

+19
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-6
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/AbstractTrait.php
+19-6Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,16 @@ public function clear(/*string $prefix = ''*/)
119119
}
120120
}
121121
$namespaceToClear = $this->namespace.$namespaceVersionToClear;
122-
$namespaceVersion = strtr(substr_replace(base64_encode(pack('V', mt_rand())), static::NS_SEPARATOR, 5), '/', '_');
122+
$namespaceVersion = self::formatNamespaceVersion(mt_rand());
123123
try {
124-
$cleared = $this->doSave([static::NS_SEPARATOR.$this->namespace => $namespaceVersion], 0);
124+
$e = $this->doSave([static::NS_SEPARATOR.$this->namespace => $namespaceVersion], 0);
125125
} catch (\Exception $e) {
126-
$cleared = false;
127126
}
128-
if ($cleared = true === $cleared || [] === $cleared) {
127+
if (true !== $e && [] !== $e){
128+
$cleared = false;
129+
$message = 'Failed to save the new namespace'.($e instanceof \Exception ? ': '.$e->getMessage() : '.');
130+
CacheItem::log($this->logger, $message, ['exception' => $e instanceof \Exception ? $e : null]);
131+
} else {
129132
$this->namespaceVersion = $namespaceVersion;
130133
$this->ids = [];
131134
}
@@ -267,12 +270,17 @@ private function getId($key): string
267270
foreach ($this->doFetch([static::NS_SEPARATOR.$this->namespace]) as $v) {
268271
$this->namespaceVersion = $v;
269272
}
273+
$e = true;
270274
if ('1'.static::NS_SEPARATOR === $this->namespaceVersion) {
271-
$this->namespaceVersion = strtr(substr_replace(base64_encode(pack('V', time())), static::NS_SEPARATOR, 5), '/', '_');
272-
$this->doSave([static::NS_SEPARATOR.$this->namespace => $this->namespaceVersion], 0);
275+
$this->namespaceVersion = self::formatNamespaceVersion(time());
276+
$e = $this->doSave([static::NS_SEPARATOR.$this->namespace => $this->namespaceVersion], 0);
273277
}
274278
} catch (\Exception $e) {
275279
}
280+
if (true !== $e && [] !== $e){
281+
$message = 'Failed to save the new namespace'.($e instanceof \Exception ? ': '.$e->getMessage() : '.');
282+
CacheItem::log($this->logger, $message, ['exception' => $e instanceof \Exception ? $e : null]);
283+
}
276284
}
277285

278286
if (\is_string($key) && isset($this->ids[$key])) {
@@ -304,4 +312,9 @@ public static function handleUnserializeCallback($class)
304312
{
305313
throw new \DomainException('Class not found: '.$class);
306314
}
315+
316+
private static function formatNamespaceVersion($value)
317+
{
318+
return strtr(substr_replace(base64_encode(pack('V', $value)), static::NS_SEPARATOR, 5), '/', '_');
319+
}
307320
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.