Skip to content

Comments

Mobian RTD Provider: use URL based cache#14481

Open
RomuloVitoi wants to merge 3 commits intoprebid:masterfrom
RomuloVitoi:master
Open

Mobian RTD Provider: use URL based cache#14481
RomuloVitoi wants to merge 3 commits intoprebid:masterfrom
RomuloVitoi:master

Conversation

@RomuloVitoi
Copy link

Type of change

  • Bugfix

  • Feature

  • New bidder adapter

  • Updated bidder adapter

  • Code style update (formatting, local variables)

  • Refactoring (no functional changes, no api changes)

  • Build related changes

  • CI related changes

  • Does this change affect user-facing APIs or examples documented on http://prebid.org?

  • Other

Description of change

The Mobian RTD Provider currently caches the response of the assessment and reuse it for every bid on the page, this does not work well for single page applications where the URL and the page content is updated. I'm updating the cache to be a Map keyed of the page URL so we can have a new assessment response in case the page URL changes.

Other information

Copilot AI review requested due to automatic review settings February 17, 2026 23:39
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 11edab9cd8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


function makeMemoizedFetch() {
let cachedResponse = null;
const cache = new Map();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound URL cache size to prevent unbounded memory growth

The new per-URL memoization uses a process-lifetime Map with no eviction, so long-lived SPA sessions that continuously change window.location.href will 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 👍 / 👎.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Mobian RTD Provider to implement URL-based caching instead of a single global cache. This change addresses the need to handle single-page applications (SPAs) where the URL and page content change without a full page reload, requiring fresh contextual assessments for each URL.

Changes:

  • Replaces single cached response with a Map-based cache keyed by page URL
  • Each unique URL now gets its own cached assessment response
  • Minor whitespace formatting change in error handler

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 67 to 78
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;
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL-based caching behavior should be covered by tests. Consider adding test cases that verify: 1) different URLs result in different cache entries, 2) subsequent calls with the same URL return cached data without making additional API calls, and 3) URL changes trigger new API calls. This will ensure the SPA behavior works as intended.

Copilot uses AI. Check for mistakes.

function makeMemoizedFetch() {
let cachedResponse = null;
const cache = new Map();
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL-based cache implemented as an unbounded Map can lead to a memory leak in single-page applications. As the user navigates to different URLs, the cache will grow indefinitely without any cleanup mechanism or size limits. Consider implementing a cache size limit (e.g., LRU cache) or a time-based expiration strategy to prevent unbounded memory growth.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@patmmccann
Copy link
Collaborator

@RomuloVitoi please resolve the bot feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants