Skip to content

fix(routePrefetch): cap prefetchCache Map to prevent unbounded memory growth #76

Description

@tmdeveloper007

Summary of What Needs to be Done

Add an LRU-style cap to the module-level prefetchCache Map in src/utils/routePrefetch.js. The cache grows without bound as users visit different routes — every unique route ever accessed is permanently retained. While clearPrefetchCache() exists, it is never called in production.

Changes

  • Define MAX_PREFETCH_CACHE_SIZE = 10
  • In prefetchRoute, before inserting a new entry, check if the cache is at capacity and evict the oldest entry (using Map's insertion-order iteration)
  • This mirrors the LRU cap pattern already used in recommendationEngine.js

Impact

Severity: Low-Medium — Unbounded memory growth in long-running SPA sessions. Users who explore many routes accumulate many cached import promises in memory over time.

Please assign this task to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gssoc:approvedApproved for GSSoC contributionlevel:beginnerSmall, low-risk change (≤3 files, ≤50 lines)type:bugSomething is broken or incorrect

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions