Skip to content
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

hotfix: Proper clearing of the ID<->URI mappings #204

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
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
36 changes: 26 additions & 10 deletions src/Services/PageRoutesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,19 @@ protected function forgetPageLocalCache(Page $page)
*/
protected function replaceIdToUriMapping(array $idToUriMapping): void
{
// Replace the ID -> URI[] mapping with the given one.
// This is done "atomically" with regards to the cache.
// Note that concurrent read and writes can result in lost updates.
// And thus in an invalid state.
Cache::forever(static::ID_TO_URI_MAPPING, $idToUriMapping);
if (empty($idToUriMapping)) {
// If the new mapping is empty, that means we've been
// cleaning the last entries. Therefore we must
// forget the cached data to properly clear it out
// and also allow proper cache invalidation
Cache::forget(static::ID_TO_URI_MAPPING);
} else {
// Replace the ID -> URI[] mapping with the given one.
// This is done "atomically" with regards to the cache.
// Note that concurrent read and writes can result in lost updates.
// And thus in an invalid state.
Cache::forever(static::ID_TO_URI_MAPPING, $idToUriMapping);
}
}

/**
Expand All @@ -323,10 +331,18 @@ protected function replaceIdToUriMapping(array $idToUriMapping): void
*/
protected function replaceUriToIdMapping(array $uriToIdMapping): void
{
// Replace the URI -> ID mapping with the given one.
// This is done "atomically" with regards to the cache.
// Note that concurrent read and writes can result in lost updates.
// And thus in an invalid state.
Cache::forever(static::URI_TO_ID_MAPPING, $uriToIdMapping);
if (empty($uriToIdMapping)) {
// If the new mapping is empty, that means we've been
// cleaning the last entries. Therefore we must
// forget the cached data to properly clear it out
// and also allow proper cache invalidation
Cache::forget(static::URI_TO_ID_MAPPING);
} else {
// Replace the URI -> ID mapping with the given one.
// This is done "atomically" with regards to the cache.
// Note that concurrent read and writes can result in lost updates.
// And thus in an invalid state.
Cache::forever(static::URI_TO_ID_MAPPING, $uriToIdMapping);
}
}
}
Loading