Commit 5f5fc1f
authored
Add LRU cache eviction to CachingStateProvider (#37214)
* Add LRU cache eviction to CachingStateProvider
Fixes #37213
Implements LRU (Least Recently Used) cache eviction to prevent
unbounded memory growth in long-running workers. Adds configurable
maxCacheSize parameter (default: 1000 entries) and maintains LRU
order using JavaScript Map's insertion order.
- Add maxCacheSize constructor parameter with default value of 1000
- Implement evictIfNeeded() to remove oldest entry when cache is full
- Implement touchCacheEntry() to move accessed items to end (LRU)
- Add comprehensive test coverage in state_provider_test.ts
This addresses the TODO comment in the code and improves reliability
for production workloads.
* Address review comments: size-based LRU eviction for CachingStateProvider
- Fixed bug: removed incorrect evictIfNeeded() call in promise callback
- Removed unnecessary this_ variable (arrow functions capture this)
- Changed from count-based to size-based eviction (similar to Python statecache.py)
- Added estimateSize() to calculate memory weight of cached values
- Default cache weight: 100MB
- Updated tests to work with weight-based eviction
* Fix prettier formatting
* Address review comments: circular references, eviction ordering, tests
- Fixed sizeof function to handle circular references using visited Set
- Fixed eviction ordering: add to cache first, then evict (fixes edge case)
- Added test for oversized item that exceeds maxCacheWeight
- Implemented custom sizeof instead of object-sizeof package (has Node.js compatibility issues)
* Address Gemini comments: fix race condition, optimize evictIfNeeded
- Fixed critical race condition in promise callback: only update cache if
the entry is still the same promise we're resolving
- Optimized evictIfNeeded: use entries() iterator and removed redundant checks1 parent 17198be commit 5f5fc1f
File tree
3 files changed
+494
-59
lines changed- sdks/typescript
- src/apache_beam/worker
- test
3 files changed
+494
-59
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments