Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

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.

keydefaultKey is a public API rename if anyone used FirebaseCacheManager.key. Prefer keeping key or a deprecated alias.


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

static RetryOptions? _retryOptions;

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.

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)) {

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.

When an instance already exists, a new retryOptions argument is silently ignored. Worth documenting, or only accepting options on first create.

return _instances[cacheKey]!;
}
_bucket = bucket ?? _bucket;

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.

_bucket = bucket ?? _bucket (and the same for _retryOptions) leaks state across instances.

FirebaseCacheManager(bucket: 'bucket-a');
FirebaseCacheManager(); // cacheKey is defaultKey, but _bucket is still 'bucket-a'

Pass the factory args directly instead:

final instance = FirebaseCacheManager._(
  key: cacheKey,
  retryOptions: retryOptions,
  bucket: bucket,
);

(or putIfAbsent and drop the statics entirely)

_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)));
Expand Down
4 changes: 2 additions & 2 deletions flutter_cache_manager_firebase/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

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.

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
Loading