From fae466f7035fe3ccd3e1bf0ffce53c7865ec64e2 Mon Sep 17 00:00:00 2001 From: Peter Keefe <16809252+percula@users.noreply.github.com> Date: Sun, 19 May 2024 21:50:21 -0400 Subject: [PATCH 1/4] feat: Add retry mechanism (WIP) --- .../lib/src/firebase_cache_manager.dart | 7 ++++++- .../lib/src/firebase_http_file_service.dart | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart b/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart index d474901f..bead1b26 100644 --- a/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart +++ b/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart @@ -1,4 +1,5 @@ import 'package:flutter_cache_manager/flutter_cache_manager.dart'; +import 'package:retry/retry.dart'; import 'firebase_http_file_service.dart'; @@ -9,10 +10,14 @@ class FirebaseCacheManager extends CacheManager { static final FirebaseCacheManager _instance = FirebaseCacheManager._(); + final RetryOptions? retryOptions; + factory FirebaseCacheManager() { return _instance; } - FirebaseCacheManager._() + FirebaseCacheManager.retry({this.retryOptions = const RetryOptions()}): super(Config(key, fileService: FirebaseHttpFileService(retryOptions: retryOptions))); + + FirebaseCacheManager._({this.retryOptions}) : super(Config(key, fileService: FirebaseHttpFileService())); } diff --git a/flutter_cache_manager_firebase/lib/src/firebase_http_file_service.dart b/flutter_cache_manager_firebase/lib/src/firebase_http_file_service.dart index c73710bc..301d0947 100644 --- a/flutter_cache_manager_firebase/lib/src/firebase_http_file_service.dart +++ b/flutter_cache_manager_firebase/lib/src/firebase_http_file_service.dart @@ -1,16 +1,31 @@ import 'package:firebase_storage/firebase_storage.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; +import 'package:retry/retry.dart'; /// [FirebaseHttpFileService] is another common file service which parses a /// firebase reference into, to standard url which can be passed to the /// standard [HttpFileService]. class FirebaseHttpFileService extends HttpFileService { + final RetryOptions? retryOptions; + + FirebaseHttpFileService({ + this.retryOptions, + }); + @override Future get(String url, {Map? headers}) async { var ref = FirebaseStorage.instance.ref().child(url); - var downloadUrl = await ref.getDownloadURL(); + String downloadUrl; + if (retryOptions != null) { + downloadUrl = await retryOptions!.retry( + () async => await ref.getDownloadURL(), + retryIf: (e) => e is FirebaseException, + ); + } else { + downloadUrl = await ref.getDownloadURL(); + } return super.get(downloadUrl); } } From decf8c8cc3753846636dabac18f141514902595d Mon Sep 17 00:00:00 2001 From: Peter Keefe <16809252+percula@users.noreply.github.com> Date: Sun, 19 May 2024 21:50:21 -0400 Subject: [PATCH 2/4] feat: Add retry mechanism (WIP) --- .../lib/src/firebase_cache_manager.dart | 2 ++ flutter_cache_manager_firebase/pubspec.yaml | 1 + 2 files changed, 3 insertions(+) diff --git a/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart b/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart index bead1b26..4e44279b 100644 --- a/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart +++ b/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart @@ -12,6 +12,8 @@ class FirebaseCacheManager extends CacheManager { final RetryOptions? retryOptions; + final RetryOptions? retryOptions; + factory FirebaseCacheManager() { return _instance; } diff --git a/flutter_cache_manager_firebase/pubspec.yaml b/flutter_cache_manager_firebase/pubspec.yaml index 7924eaf8..18bd7396 100644 --- a/flutter_cache_manager_firebase/pubspec.yaml +++ b/flutter_cache_manager_firebase/pubspec.yaml @@ -13,6 +13,7 @@ dependencies: firebase_storage: '>=12.0.0 <13.0.0' path_provider: ^2.1.2 path: ^1.9.0 + retry: ^3.1.2 dev_dependencies: flutter_lints: ^4.0.0 From 84cd02be3ba9fd12fab92888afd4554e4a7ce9ca Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Wed, 31 Jul 2024 21:59:50 +0200 Subject: [PATCH 3/4] Fix --- .../lib/src/firebase_cache_manager.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart b/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart index 4e44279b..4868c18e 100644 --- a/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart +++ b/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart @@ -12,14 +12,14 @@ class FirebaseCacheManager extends CacheManager { final RetryOptions? retryOptions; - final RetryOptions? retryOptions; - factory FirebaseCacheManager() { return _instance; } - FirebaseCacheManager.retry({this.retryOptions = const RetryOptions()}): super(Config(key, fileService: FirebaseHttpFileService(retryOptions: retryOptions))); + FirebaseCacheManager.retry({this.retryOptions = const RetryOptions()}) + : super(Config(key, + fileService: FirebaseHttpFileService(retryOptions: retryOptions))); - FirebaseCacheManager._({this.retryOptions}) + FirebaseCacheManager._(this.retryOptions) : super(Config(key, fileService: FirebaseHttpFileService())); } From 530f20c31836a4b7ee37c1f24af773439b05fafd Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Wed, 31 Jul 2024 22:02:34 +0200 Subject: [PATCH 4/4] Fix --- flutter_cache_manager_firebase/CHANGELOG.md | 7 +++++++ .../lib/src/firebase_cache_manager.dart | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/flutter_cache_manager_firebase/CHANGELOG.md b/flutter_cache_manager_firebase/CHANGELOG.md index 2c1a7547..6628afc3 100644 --- a/flutter_cache_manager_firebase/CHANGELOG.md +++ b/flutter_cache_manager_firebase/CHANGELOG.md @@ -1,22 +1,29 @@ ## [2.0.3] - 2024-07-23 + * Updates dependencies ([#457](https://github.com/Baseflow/flutter_cache_manager/pull/457)) ## [2.0.2] - 2024-04-25 + * Updates dependencies to their latest versions. ## [2.0.1] - 2021-08-27 + * Update dependencies ## [2.0.0] - 2021-05-28 + * Update to null safety ## [1.1.0] - 2021-01-14 + * Update Firebase dependency ## [1.1.0-beta] - 2020-10-02 + * Update CacheManager dependency to 2.x.x. ## [1.0.1] - Update firebase dependency + * Added support for version 4.x.x ## [1.0.0] - Initial release diff --git a/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart b/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart index 4868c18e..08c44187 100644 --- a/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart +++ b/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart @@ -8,7 +8,7 @@ import 'firebase_http_file_service.dart'; class FirebaseCacheManager extends CacheManager { static const key = 'firebaseCache'; - static final FirebaseCacheManager _instance = FirebaseCacheManager._(); + static final FirebaseCacheManager _instance = FirebaseCacheManager._(null); final RetryOptions? retryOptions;