From 00855895a85dc04db70012a1c8a5ce643db39765 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 23 Sep 2018 09:05:27 +0200 Subject: [PATCH] [Cache] prevent getting older entries when the version key is evicted --- .../Component/Cache/Traits/AbstractTrait.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Cache/Traits/AbstractTrait.php b/src/Symfony/Component/Cache/Traits/AbstractTrait.php index ec60fe79c4..87aeba9e7b 100644 --- a/src/Symfony/Component/Cache/Traits/AbstractTrait.php +++ b/src/Symfony/Component/Cache/Traits/AbstractTrait.php @@ -106,14 +106,7 @@ trait AbstractTrait { $this->deferred = array(); if ($cleared = $this->versioningIsEnabled) { - $namespaceVersion = 2; - try { - foreach ($this->doFetch(array('@'.$this->namespace)) as $v) { - $namespaceVersion = 1 + (int) $v; - } - } catch (\Exception $e) { - } - $namespaceVersion .= ':'; + $namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), ':', 5); try { $cleared = $this->doSave(array('@'.$this->namespace => $namespaceVersion), 0); } catch (\Exception $e) { @@ -247,6 +240,10 @@ trait AbstractTrait foreach ($this->doFetch(array('@'.$this->namespace)) as $v) { $this->namespaceVersion = $v; } + if ('1:' === $this->namespaceVersion) { + $this->namespaceVersion = substr_replace(base64_encode(pack('V', time())), ':', 5); + $this->doSave(array('@'.$this->namespace => $this->namespaceVersion), 0); + } } catch (\Exception $e) { } }