8000 [Cache] prevent getting older entries when the version key is evicted · symfony/symfony@0085589 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0085589

Browse files
[Cache] prevent getting older entries when the version key is evicted
1 parent 9bc774c commit 0085589

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,7 @@ public function clear()
106106
{
107107
$this->deferred = array();
108108
if ($cleared = $this->versioningIsEnabled) {
109-
$namespaceVersion = 2;
110-
try {
111-
foreach ($this->doFetch(array('@'.$this->namespace)) as $v) {
112-
$namespaceVersion = 1 + (int) $v;
113-
}
114-
} catch (\Exception $e) {
115-
}
116-
$namespaceVersion .= ':';
109+
$namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), ':', 5);
117110
try {
118111
$cleared = $this->doSave(array('@'.$this->namespace => $namespaceVersion), 0);
119112
} catch (\Exception $e) {
@@ -247,6 +240,10 @@ private function getId($key)
247240
foreach ($this->doFetch(array('@'.$this->namespace)) as $v) {
248241
$this->namespaceVersion = $v;
249242
}
243+
if ('1:' === $this->namespaceVersion) {
244+
$this->namespaceVersion = substr_replace(base64_encode(pack('V', time())), ':', 5);
245+
$this->doSave(array('@'.$this->namespace => $this->namespaceVersion), 0);
246+
}
250247
} catch (\Exception $e) {
251248
}
252249
}

0 commit comments

Comments
 (0)
0