Skip to content

Support for Caching on Web using IndexedDB - #504

Open
ben-milanko wants to merge 24 commits into
Baseflow:developfrom
Railway-Engineering-Solutions:develop
Open

Support for Caching on Web using IndexedDB#504
ben-milanko wants to merge 24 commits into
Baseflow:developfrom
Railway-Engineering-Solutions:develop

Conversation

@ben-milanko

Copy link
Copy Markdown
Contributor

✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)

Feature

⤵️ What is the current behavior?

Flutter web has no persistent caching. Cache is stored only in memory and lost on page refresh.

🆕 What is the new behavior (if this is a feature change)?

Cache metadata and files stored in IndexedDB. Data persists across page refreshes and browser sessions.

💥 Does this PR introduce a breaking change?

No - Non-breaking change. Works automatically without code changes. SDK 3.6.0+ now required.

🐛 Recommendations for testing

  1. Switch test app to use the repo in this PR
  2. Download files in app
  3. Refresh app and observe new caching behaviour
  4. Check IndexedDB in Chrome DevTools

📝 Links to relevant issues/docs

#480
#339
#361
#122

🤔 Checklist before submitting

  • All projects build - Appears to be issues getting the example builds to work, but I have tested it in my apps that use flutter_cache_manager and cached_network_image
  • Follows style guide lines (code style guide)
  • Relevant documentation was updated
  • Rebased onto current develop

@ben-milanko ben-milanko mentioned this pull request Mar 30, 2026
@ali2236

ali2236 commented Jun 25, 2026

Copy link
Copy Markdown

Tested it and it works very well on my app.

ben-milanko and others added 14 commits September 5, 2026 13:53
…ync-and-deps

# Conflicts:
#	flutter_cache_manager/example/macos/Flutter/GeneratedPluginRegistrant.swift
#	flutter_cache_manager/example/pubspec.yaml
#	flutter_cache_manager/lib/src/config/_config_web.dart
#	flutter_cache_manager/pubspec.yaml
Raise direct dependency floors to the latest published versions
(clock 1.1.3, path_provider 2.1.6, sqflite 2.4.3, build_runner 2.16.1,
mockito 5.8.1, web 1.1.1) and record the fork's IndexedDB web support
alongside the upstream sync in the changelog.

Also picks up the analyzer excludes the Flutter 3.47 toolchain writes
into analysis_options.yaml on pub get.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TCmKSRuHNETmfGu2TffVzo
Upstream CI now runs `dart format --set-exit-if-changed .`, and the
fork's IndexedDB repository, connection pool, file system and example
were still in the pre-3.7 style.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TCmKSRuHNETmfGu2TffVzo
CI pinned Flutter 3.44.4 while the packages now build against 3.47.1.
Raising the pin surfaces two use_super_parameters findings in upstream
code, so convert both constructors to super parameters and drop the
web_helper import that becomes redundant as a result.

`flutter analyze` is clean for both packages on 3.47.1.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TCmKSRuHNETmfGu2TffVzo
- Introduced `CancellationToken` class to manage request cancellations.
- Updated `CacheManager`, `BaseCacheManager`, and `FileService` interfaces to accept `CancellationToken`.
- Enhanced file fetching methods to throw `CancelledException` when requests are cancelled.
- Added tests for cancellation functionality in `HttpFileService` and `CancellationToken` behavior.
- Updated `ImageCacheManager` methods to accept `CancellationToken` for file fetching operations.
- Ensured cancellation support is integrated into both direct file retrieval and resized image handling.
- Changed the constructor to ensure a default http.Client is used if none is provided.
- Updated request handling to utilize AbortableRequest for better cancellation support.
- Modified tests to reflect the new behavior, ensuring that cancellation after response completion does not throw an exception.
- Added checks to prevent operations on already cancelled requests in `CancellationToken`.
- Enhanced `WebHelper` to handle cancellation before starting downloads and during queue processing.
- Ensured proper cleanup of subjects associated with cancelled requests to prevent memory leaks.
- Added multiple cancellation checks throughout the file update process in `WebHelper`.
- Ensured that cancellation is checked before and after asynchronous operations, including downloads and file saves.
- Updated `_manageResponse` and `_saveFile` methods to accept `CancellationToken` for improved cancellation support.
Rebuilds test/mock.mocks.dart against mockito 5.8.1 and applies
dart format to the cancellation changes so CI's format check passes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TCmKSRuHNETmfGu2TffVzo
…am-sync-and-deps

Sync with Baseflow upstream and upgrade dependencies
flutter_cache_manager_firebase depends on flutter_cache_manager ^3.4.2
from pub.dev, which has no CancellationToken. FirebaseHttpFileService
overrides HttpFileService.get, so once that signature gained a
cancellationToken parameter the package stopped analyzing:

  error - Undefined class 'CancellationToken'
  error - The named parameter 'cancellationToken' isn't defined

Override the dependency with the sibling package in this repository, so
the two move together. Overrides are ignored by consumers, so this does
not affect anyone depending on the published package.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TCmKSRuHNETmfGu2TffVzo
…-request-cancellation-2

Network request cancellation (rebased onto the upstream sync)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants