Skip to content

Commit

Permalink
bug #28561 [Cache] prevent getting older entries when the version key…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
fabpot committed Sep 26, 2018
2 parents 3ad2328 + 0085589 commit 2a605c2
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Symfony/Component/Cache/Traits/AbstractTrait.php
Expand Up @@ -106,14 +106,7 @@ public function clear()
{
$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) {
Expand Down Expand Up @@ -247,6 +240,10 @@ private function getId($key)
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) {
}
}
Expand Down

0 comments on commit 2a605c2

Please sign in to comment.