Fix cascading LRU eviction during prefetch batches (#89766)
When links remount (e.g. toggling between tabs), the prefetch scheduler processes tasks across multiple async batches due to network bandwidth limits. Between batches, LRU cleanup could fire and evict cache entries for tasks that hadn't been processed yet. Those tasks would then see cache misses, fetch fresh data, push the LRU over the limit again, and trigger more cleanup, cascading through nearly all entries. We fix this by moving LRU cleanup into the prefetch scheduler loop. Instead of scheduling cleanup independently via `requestIdleCallback`/`setTimeout`, the LRU module pings the scheduler when the cache exceeds its size limit, and the scheduler runs cleanup only when it's fully idle (no queued tasks, no in-flight requests). At that point, all active prefetch tasks have finished reading from the cache, so eviction targets genuinely stale data. The tradeoff is that the cache can temporarily exceed its size limit while prefetch tasks are in flight. This was already the case since cleanup was always async, but it's now more explicit since cleanup is tied to the scheduler settling rather than the next idle callback.
Showing
Please
register
or
sign in
to comment