-
-
Notifications
You must be signed in to change notification settings - Fork 511
Fix bucket name being reused between instances of different buckets #496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,22 +6,27 @@ import 'firebase_http_file_service.dart'; | |
| /// Use [FirebaseCacheManager] if you want to download files from firebase storage | ||
| /// and store them in your local cache. | ||
| class FirebaseCacheManager extends CacheManager { | ||
| static const key = 'firebaseCache'; | ||
| static const defaultKey = 'firebaseCache'; | ||
|
|
||
| static final FirebaseCacheManager _instance = | ||
| FirebaseCacheManager._(retryOptions: _retryOptions, bucket: _bucket); | ||
| static final Map<String, FirebaseCacheManager> _instances = {}; | ||
|
|
||
| static RetryOptions? _retryOptions; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These statics are no longer needed once each instance owns its own bucket/retryOptions. Keeping them causes cross-instance leakage. |
||
|
|
||
| static String? _bucket; | ||
|
|
||
| factory FirebaseCacheManager({RetryOptions? retryOptions, String? bucket}) { | ||
| _bucket = bucket; | ||
| _retryOptions = retryOptions; | ||
| return _instance; | ||
| final cacheKey = bucket ?? defaultKey; | ||
| if (_instances.containsKey(cacheKey)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When an instance already exists, a new |
||
| return _instances[cacheKey]!; | ||
| } | ||
| _bucket = bucket ?? _bucket; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Pass the factory args directly instead: (or |
||
| _retryOptions = retryOptions ?? _retryOptions; | ||
| final instance = FirebaseCacheManager._(key: cacheKey, retryOptions: _retryOptions, bucket: _bucket); | ||
| _instances[cacheKey] = instance; | ||
| return instance; | ||
| } | ||
|
|
||
| FirebaseCacheManager._({RetryOptions? retryOptions, String? bucket}) | ||
| FirebaseCacheManager._({required String key, RetryOptions? retryOptions, String? bucket}) | ||
| : super(Config(key, | ||
| fileService: FirebaseHttpFileService( | ||
| retryOptions: retryOptions, bucket: bucket))); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,12 @@ dependencies: | |
| flutter: | ||
| sdk: flutter | ||
| flutter_cache_manager: ^3.4.1 | ||
| firebase_storage: '>=12.0.0 <13.0.0' | ||
| firebase_storage: ^13.0.0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This version bump should preferably be done in a different PR |
||
| path_provider: ^2.1.4 | ||
| path: ^1.9.0 | ||
| retry: ^3.1.2 | ||
|
|
||
| dev_dependencies: | ||
| flutter_lints: ^4.0.0 | ||
| flutter_lints: ^6.0.0 | ||
| flutter_test: | ||
| sdk: flutter | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key→defaultKeyis a public API rename if anyone usedFirebaseCacheManager.key. Prefer keeping key or a deprecated alias.