fix(pages-router): add bounded eviction to client-side data cache (sdc/sbc)#95355
Draft
sleitor wants to merge 1 commit into
Draft
fix(pages-router): add bounded eviction to client-side data cache (sdc/sbc)#95355sleitor wants to merge 1 commit into
sleitor wants to merge 1 commit into
Conversation
…c/sbc) The sdc/sbc (Server Data Cache / Server Background Cache) objects in the Pages Router grew without bound: every route visited added a Promise to the plain-object cache and nothing ever removed them, causing a memory leak that grows with the number of unique pages visited in a long-lived session (issue vercel#91484, reported by iamakulov). This change wraps the cache initializer in a Proxy-based factory (createDataCache) that enforces a maximum of 50 cache entries using a FIFO eviction policy. When the 51st unique key is written, the oldest entry is deleted before the new one is stored. All existing call sites that read, write, or delete cache keys via bracket notation continue to work without modification. The constant SDC_MAX_ENTRIES (50 routes) matches common LRU sizes used in other parts of the codebase and is conservative enough to avoid any observable regressions while still bounding memory use to a reasonable level for production sessions. Fixes vercel#91484
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
sdc/sbc(Server Data Cache / Server Background Cache) objects in the Pages Router grew without bound: every route visited added a Promise to the plain-object cache and nothing ever removed them, causing a memory leak that grows with the number of unique pages visited in a long-lived session (reported in #91484 by @iamakulov).What
Wraps the cache initializer in a Proxy-based factory (
createDataCache) that enforces a maximum of 50 cache entries using a FIFO eviction policy. When the 51st unique key is written, the oldest entry is deleted before the new one is stored. All existing call sites that read, write, or delete cache keys via bracket notation continue to work without modification.The constant
SDC_MAX_ENTRIES(50 routes) matches common LRU sizes used in other parts of the codebase and is conservative enough to avoid observable regressions while still bounding memory use for production sessions.Why
Previously there was no eviction at all — the cache was a plain object with no size limit. This is a low-risk, zero-call-site-change fix.
Fixes #91484