fix(streaming): add LRU cache limit to InitCache #4935
+839
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements a bounded LRU (Least Recently Used) cache in
InitCacheto prevent memory leaks during long playback sessions with multiple periods or stream switches.Changes
InitCache.js
MAX_CACHE_SIZE = 50constantremoveStream(streamId)method for explicit cleanupgetStats()method for debugging/testingMediaPlayer.js
getInitCache()method for testing accesssamples/cache/initcache-test.html
Test Results ✅
Comparison:
developmentvsfix/initcache-lru-limitdevelopmentTest 3: Cache Overflow (Synthetic) Results
Branch:
development(without fix)Branch:
fix/initcache-lru-limit(with fix)Test Page
A test page is included at
samples/cache/initcache-test.htmlwith three test modes:Test 1: Quality Switch Stress Test
Test 2: Stream Switch Stress Test
Test 3: Cache Overflow Test (Synthetic)
How to Run Tests
Design Decisions
Cache size of 50: A conservative default that should cover most use cases
LRU vs. TTL: LRU chosen because:
removeStream()method: Allows explicit cleanup when a stream endsExpected Impact
Testing Checklist
Breaking Changes
None. Cache behavior is transparent to consumers.
🤖 Generated with Claude Code
Fixes #4932