Skip to content

[Performance] Image cache unbounded — fills device storage during heavy course catalog browsing #677

Description

@RUKAYAT-CODER

Overview

src/services/imageCache.ts caches downloaded images to the file system via expo-file-system without enforcing a total size limit. Heavy course browsing accumulates hundreds of megabytes in the app cache directory, triggering OS-level storage warnings and unexpected cache eviction behavior.

Specifications

Features:

  • Image cache enforces 100MB maximum size
  • When 80% full, least-recently-used images evicted automatically
  • Cache size exposed as metric in memoryPressureService
  • Cache cleared on memoryPressureService critical event

Tasks:

  • Add LRU eviction to imageCache.ts with MAX_CACHE_SIZE_BYTES = 100 * 1024 * 1024
  • Track total cached bytes and access timestamps per entry
  • Implement evictLRU(targetBytesToFree: number) method
  • Subscribe imageCache.clearNonCritical() to memoryPressureService critical event
  • Add unit test confirming eviction fires at 80MB when 81st MB pushed

Impacted Files:

  • src/services/imageCache.ts
  • src/components/common/CachedImage.tsx

Acceptance Criteria

  • Image cache does not exceed 100MB on disk
  • LRU eviction fires when cache reaches 80MB
  • Critical memory pressure clears all non-pinned cached images
  • Unit test confirms eviction at 80% threshold

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveIssues in the Stellar wave programbugSomething isn't workingperformancePerformance issue or optimization

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions