Skip to content

Await store.putFile so cache info is persisted #492 - #518

Merged
rickdijk merged 5 commits into
Baseflow:mainfrom
AzazelSensei:fix/await-putfile-persist
Sep 17, 2026
Merged

rickdijk merged 5 commits into
Baseflow:mainfrom
AzazelSensei:fix/await-putfile-persist

Conversation

@AzazelSensei

@AzazelSensei AzazelSensei commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

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

Bug fix

⤵️ What is the current behavior?

putFile, putFileStream, and WebHelper start store.putFile and return without waiting. The file is on disk, but the cache-info row (and its id) may not be written yet.

That matches #492: removeFile after getFileStream can no-op because CacheObject.id is still null, and a crash right after download can drop the entry.

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

Those paths now await persist. After they complete, the store has the object and an id, so a follow-up removeFile actually deletes it.

💥 Does this PR introduce a breaking change?

Yes. If the cache-info repository write fails, putFile/putFileStream now throw and downloads/getFileStream error the stream. On develop those calls still returned the file. Bytes may already be on disk.

🐛 Recommendations for testing

flutter test in flutter_cache_manager. New cases delay store.putFile and fail if the caller returns early.

📝 Links to relevant issues/docs

Fixes #492

🤔 Checklist before submitting

  • All projects build
  • Follows style guide lines (code style guide)
  • Relevant documentation was updated
  • Rebased onto current develop

@rickdijk rickdijk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address my comments so we can proceed with this fix

Comment thread flutter_cache_manager/lib/src/web/web_helper.dart
Comment thread flutter_cache_manager/test/cache_manager_test.dart
Comment thread flutter_cache_manager/test/cache_manager_test.dart
Comment thread flutter_cache_manager/test/web_helper_test.dart Outdated
Comment thread flutter_cache_manager/test/web_helper_test.dart Outdated
@AzazelSensei

Copy link
Copy Markdown
Contributor Author

Added the try/catch on _removeOldFile, switched the persist tests to Completers, and added the removeFile-after-putFile case.

@AzazelSensei
AzazelSensei force-pushed the fix/await-putfile-persist branch from a0cab87 to 6312786 Compare August 24, 2026 06:28
@AzazelSensei AzazelSensei reopened this Aug 24, 2026
Comment thread flutter_cache_manager/test/cache_manager_test.dart Outdated
Comment thread flutter_cache_manager/test/cache_manager_test.dart Outdated
Comment thread flutter_cache_manager/test/web_helper_test.dart Outdated
Comment thread flutter_cache_manager/lib/src/web/web_helper.dart
@AzazelSensei
AzazelSensei force-pushed the fix/await-putfile-persist branch from 968f35c to a4509a4 Compare September 15, 2026 23:23
@AzazelSensei

Copy link
Copy Markdown
Contributor Author

Dropped the extra Config import, wrapped the test lines dart format was failing on, rebased onto develop, and noted the breaking persist-error behavior in the PR body and CHANGELOG.

@rickdijk
rickdijk changed the base branch from develop to main September 16, 2026 00:18
@rickdijk
rickdijk force-pushed the fix/await-putfile-persist branch from a4509a4 to 4c82fd8 Compare September 16, 2026 04:00
putFile, putFileStream, and downloads started persist without waiting.
After those calls returned, CacheObject.id could still be null, so
removeFile skipped the entry and a process exit could lose the info.

Fixes Baseflow#492
Catch FileSystemException when deleting a stale cache file.
Drop the extra Config import, wrap the long test lines, and document
that a failed cache-info write now surfaces to the caller.
@rickdijk
rickdijk force-pushed the fix/await-putfile-persist branch from 4c82fd8 to 8a674ca Compare September 16, 2026 04:27

@rickdijk rickdijk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move CHANGELOG to a new version 3.4.4 and update the pubspec.yaml of this package to that version too. Then we can merge

Comment thread flutter_cache_manager/CHANGELOG.md Outdated
Move the persist-await changelog entry out of 3.4.3 and set the package version.
@AzazelSensei

Copy link
Copy Markdown
Contributor Author

Moved the changelog entry to 3.4.4 and bumped the package version in pubspec.yaml.

@rickdijk

Copy link
Copy Markdown
Contributor

Moved the changelog entry to 3.4.4 and bumped the package version in pubspec.yaml.

Seems like the formatter still requests fixing.

@rickdijk rickdijk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix formatting

@AzazelSensei

Copy link
Copy Markdown
Contributor Author

Ran dart format on the persist-await test.

@rickdijk
rickdijk merged commit 758e206 into Baseflow:main Sep 17, 2026
8 checks passed
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.

CacheManager: does not wait for data to be persisted. Potential consistency issue

2 participants