-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Mobian RTD Provider: use URL based cache #14481
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,14 +65,16 @@ const logMessage = (...args) => { | |
| }; | ||
|
|
||
| function makeMemoizedFetch() { | ||
| let cachedResponse = null; | ||
| const cache = new Map(); | ||
|
||
| return async function () { | ||
| if (cachedResponse) { | ||
| return Promise.resolve(cachedResponse); | ||
| const pageUrl = window.location.href; | ||
| if (cache.has(pageUrl)) { | ||
| return Promise.resolve(cache.get(pageUrl)); | ||
| } | ||
| try { | ||
| const response = await fetchContextData(); | ||
| cachedResponse = makeDataFromResponse(response); | ||
| const cachedResponse = makeDataFromResponse(response); | ||
| cache.set(pageUrl, cachedResponse); | ||
| return cachedResponse; | ||
|
Comment on lines
67
to
78
|
||
| } catch (error) { | ||
| logMessage('error', error); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new per-URL memoization uses a process-lifetime
Mapwith no eviction, so long-lived SPA sessions that continuously changewindow.location.hrefwill accumulate entries indefinitely and retain all prior context payloads in memory. This is a regression from the previous single-entry cache footprint and can degrade performance over time in production; consider limiting the cache (e.g., last URL only, TTL, or LRU max size).Useful? React with 👍 / 👎.