@@ -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.
88class 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)));
0 commit comments