Repository navigation
feat(web): persist the cache in IndexedDB - #547
Open
ben-milanko wants to merge 1 commit into
Open
ben-milanko wants to merge 1 commit into
ben-milanko wants to merge 1 commit into
Conversation
On web, files and cache info are now stored in IndexedDB instead of memory, so the cache survives reloads and browser restarts (Baseflow#480, Baseflow#339, Baseflow#361, Baseflow#122). This is the new web default and is documented in the README; MemoryCacheSystem with NonStoringObjectProvider keeps the old in-memory behavior. - One shared schema for the file store and the cache info repository, applied by a reference-counted connection pool, so close() really closes and blocked upgrades are logged. - Files are written in 512 KiB chunks as they download; openRead streams chunks, exists() uses count() and length() reads only the header. - When the quota is reached, least recently used entries are evicted together with their data chunks, and the failed write is retried once. - Transactions request relaxed durability. - CacheStore checks existence with await file.exists() on every platform and treats a file a concurrent removal already deleted as removed. - Browser tests: flutter test --platform chrome test/web (also --wasm). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)
Feature: persistent caching on web, stored in IndexedDB. This is the first of the two pull requests suggested in the review of #504. Request cancellation is in a separate PR.
On web the cache is held in memory (
MemoryCacheSystemplusNonStoringObjectProvider), so every page reload or browser restart starts with an empty cache (#480, #339, #361, #122).🆕 What is the new behavior (if this is a feature change)?
flutter_cache_manager_<key>.close()really closes the connection and blocked upgrades are logged.openReadstreams chunk by chunk,exists()usescount(), andlength()reads only a small header, so no whole file is held in memory.CacheStorechecks existence withawait file.exists()on every platform. A file that a concurrent removal already deleted is treated as removed.file_system.dartstays exported.💥 Does this PR introduce a breaking change?
No API changes. Behaviour on web changes: IndexedDB becomes the default storage. This is documented in the README and the CHANGELOG. Apps that want the previous behaviour can pass
fileSystem: MemoryCacheSystem()andrepo: NonStoringObjectProvider()toConfig. If you would prefer IndexedDB to be opt-in throughConfig, that is a small change and I'm happy to make it.🐛 Recommendations for testing
flutter test --platform chrome test/web(also passes with--wasm): 19 browser tests covering the repository, chunked file writes and reads, the connection pool and quota eviction.flutter test: 146 VM tests pass.flutter build web --wasminexample/builds.📝 Links to relevant issues/docs
#480, #339, #361, #122. Follows the review of #504.
🤔 Checklist before submitting