8000 bug #28561 [Cache] prevent getting older entries when the version key… · symfony/symfony@2a605c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a605c2

Browse files
committed
bug #28561 [Cache] prevent getting older entries when the version key is evicted (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [Cache] prevent getting older entries when the version key is evicted | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28445 | License | MIT | Doc PR | - As described in linked issue, using a strategy described in https://github.com/memcached/memcached/wiki/ProgrammingTricks#deleting-by-namespace Commits ------- 0085589 [Cache] prevent getting older entries when the version key is evicted
2 parents 3ad2328 + 0085589 commit 2a605c2

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