Skip to content

Commit b36b3f3

Browse files
committed
Fix bucket name being reused between instances of different buckets
1 parent 8069727 commit b36b3f3

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@ import 'firebase_http_file_service.dart';
66
/// Use [FirebaseCacheManager] if you want to download files from firebase storage
77
/// and store them in your local cache.
88
class FirebaseCacheManager extends CacheManager {
9-
static const key = 'firebaseCache';
9+
static const defaultKey = 'firebaseCache';
1010

11-
static final FirebaseCacheManager _instance =
12-
FirebaseCacheManager._(retryOptions: _retryOptions, bucket: _bucket);
11+
static final Map<String, FirebaseCacheManager> _instances = {};
1312

1413
static RetryOptions? _retryOptions;
1514

1615
static String? _bucket;
1716

1817
factory FirebaseCacheManager({RetryOptions? retryOptions, String? bucket}) {
19-
_bucket = bucket;
20-
_retryOptions = retryOptions;
21-
return _instance;
18+
final cacheKey = bucket ?? defaultKey;
19+
if (_instances.containsKey(cacheKey)) {
20+
return _instances[cacheKey]!;
21+
}
22+
_bucket = bucket ?? _bucket;
23+
_retryOptions = retryOptions ?? _retryOptions;
24+
final instance = FirebaseCacheManager._(key: cacheKey, retryOptions: _retryOptions, bucket: _bucket);
25+
_instances[cacheKey] = instance;
26+
return instance;
2227
}
2328

24-
FirebaseCacheManager._({RetryOptions? retryOptions, String? bucket})
29+
FirebaseCacheManager._({required String key, RetryOptions? retryOptions, String? bucket})
2530
: super(Config(key,
2631
fileService: FirebaseHttpFileService(
2732
retryOptions: retryOptions, bucket: bucket)));

flutter_cache_manager_firebase/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies:
1010
flutter:
1111
sdk: flutter
1212
flutter_cache_manager: ^3.4.1
13-
firebase_storage: '13.0.0'
13+
firebase_storage: ^13.0.0
1414
path_provider: ^2.1.4
1515
path: ^1.9.0
1616
retry: ^3.1.2

0 commit comments

Comments
 (0)