Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2abdaf2

Browse files
committed
[Cache] Use random numbers for initialization of tag version
1 parent a568510 commit 2abdaf2

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,21 +412,19 @@ private function getTagVersions(array $tagsByKey, array $invalidatedTags = [])
412412
return $tagVersions;
413413
}
414414

415-
$tod = gettimeofday();
416-
$newVersion = $tod['sec'] * 1000000 + $tod['usec'];
417415
$updatedTags = [];
418416
foreach ($this->tags->getItems(array_keys($tags)) as $tag => $version) {
419417
$tag = $tags[$tag];
420418

421419
if ($version->isHit()) {
422420
$tagVersions[$tag] = $version->get();
423421
} else {
424-
$tagVersions[$tag] = $newVersion;
425-
$updatedTags[$tag] = $version->set($newVersion);
422+
$tagVersions[$tag] = mt_rand(0, \PHP_INT_MAX);
423+
$updatedTags[$tag] = $version->set($tagVersions[$tag]);
426424
}
427425

428-
if (isset($invalidatedTags[$tag])) {
429-
$updatedTags[$tag] = $version->set(++$tagVersions[$tag]);
426+
if (isset($invalidatedTags[$tag]) && !isset($updatedTags[$tag])) {
427+
$updatedTags[$tag] = $version->set(\PHP_INT_MAX === $tagVersions[$tag] ? 0 : ++$tagVersions[$tag]);
430428
}
431429
$this->knownTagVersions[$tag] = [$now, $tagVersions[$tag]];
432430
}

0 commit comments

Comments
 (0)