8000 [Cache] Add missing log when saving namespace · symfony/symfony@8e26644 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e26644

Browse files
developer-avnicolas-grekas
authored andcommitted
[Cache] Add missing log when saving namespace
1 parent 4145222 commit 8e26644

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

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

Lines 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(int $value): string
317+
{
318+
return strtr(substr_replace(base64_encode(pack('V', $value)), static::NS_SEPARATOR, 5), '/', '_');
319+
}
307320
}

0 commit comments

Comments
 (0)
0