client: Add VideoMediaCache create/clear guards and document cache key behaviour#6561
Conversation
- VideoMediaCache.create() now returns VideoMediaCache? and wraps SimpleCache construction in a try-catch; a stale directory lock from a prior crash no longer aborts ChatClient initialisation — video caching is silently disabled instead. - VideoCacheConfig KDoc notes that cache entries are keyed by URL path only (query parameters are stripped). - LRU eviction test comment acknowledges the wall-clock dependency of the Thread.sleep spacing and what to do if the test becomes flaky. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
SDK Size Comparison 📏
|
`clearCacheAndTemporaryFiles` decided whether to delete the video cache directory based on `VideoMediaCache.clearAll()`, a process-wide boolean that does not line up with the single directory being deleted. When it reported no live cache, the fallback `deleteRecursively()` could run after another thread created a new `SimpleCache` for the same directory, corrupting Media3's on-disk index and lock. Replace `clearAll()` with `clearOrDelete(cacheDir, deleteOnDisk)`, which decides per directory under the registry lock: clear a live cache in place, or delete on disk when none owns it. Holding the lock across the check and the delete keeps a concurrent `create()` from registering a cache mid-delete. This also decouples the cleanup test from global registry state. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
In VideoMediaCache.create, the StandaloneDatabaseProvider is opened before the SimpleCache is constructed. When construction throws (e.g. a stale directory lock), the catch returned null without closing the provider, leaking its database connection on that path. Close it in the catch, guarded like release() does, since close() can itself throw. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
VideoMediaCache create/clear guards and document cache key behaviour
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
WalkthroughVideo cache clearing now atomically chooses between clearing a live cache and deleting an unowned directory. Cache creation returns ChangesVideo cache lifecycle
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |


Goal
Backport of the review fixes from #6542 to
v6.Guard against a crash during ChatClient initialisation when the SimpleCache
directory lock is stale (e.g. left by a prior process crash), and clarify
cache key semantics in the public docs.
Implementation
VideoMediaCache.create()now returnsVideoMediaCache?and wrapsSimpleCacheconstruction in atry-catch. A stale directory lock nolonger aborts
ChatClientinitialisation — video caching is silentlydisabled instead.
ChatClient.ktalready uses?.let {}so the nullablereturn is handled transparently.
VideoCacheConfigKDoc: added a note that cache entries are keyed by URLpath only (query parameters are stripped).
dependency of
Thread.sleepspacing and what to do if the test flakes.UI Changes
No UI changes.
Testing
./gradlew :stream-chat-android-client:testDebugUnitTest --tests "*.cache.*"Summary by CodeRabbit
Bug Fixes
Documentation