8000 [Cache] Decrease the probability of invalidation loss on tag eviction by sbelyshkin · Pull Request #43301 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] Decrease the probability of invalidation loss on tag eviction #43301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Cache] Use random numbers for initialization of tag version
  • Loading branch information
sbelyshkin committed Oct 10, 2021
commit 2abdaf24f51b5acf21b606e6e8545ba0192823e0
10 changes: 4 additions & 6 deletions src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,21 +412,19 @@ private function getTagVersions(array $tagsByKey, array $invalidatedTags = [])
return $tagVersions;
}

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

if ($version->isHit()) {
$tagVersions[$tag] = $version->get();
} else {
$tagVersions[$tag] = $newVersion;
$updatedTags[$tag] = $version->set($newVersion);
$tagVersions[$tag] = mt_rand(0, \PHP_INT_MAX);
$updatedTags[$tag] = $version->set($tagVersions[$tag]);
}

if (isset($invalidatedTags[$tag])) {
$updatedTags[$tag] = $version->set(++$tagVersions[$tag]);
if (isset($invalidatedTags[$tag]) && !isset($updatedTags[$tag])) {
$updatedTags[$tag] = $version->set(\PHP_INT_MAX === $tagVersions[$tag] ? 0 : ++$tagVersions[$tag]);
}
$this->knownTagVersions[$tag] = [$now, $tagVersions[$tag]];
}
Expand Down
0