Skip to content

Commit 3de47cf

Browse files
CacheSettings constructor feedback from Cynthia
1 parent 16cf964 commit 3de47cf

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

packages/firebase_data_connect/firebase_data_connect/lib/src/cache/cache_data_types.dart

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,26 @@ class CacheSettings {
3333
/// Duration for which cache is used before revalidation with server
3434
final Duration maxAge;
3535

36-
const CacheSettings(
37-
{this.storage = kIsWeb ? CacheStorage.memory : CacheStorage.persistent,
38-
this.maxSizeBytes = kIsWeb ? 40000000 : 100000000,
39-
this.maxAge = Duration.zero});
36+
// Internal const constructor
37+
const CacheSettings._internal({
38+
required this.storage,
39+
required this.maxSizeBytes,
40+
required this.maxAge,
41+
});
42+
43+
// Factory constructor to handle the logic
44+
factory CacheSettings({
45+
CacheStorage? storage,
46+
int? maxSizeBytes,
47+
Duration maxAge = Duration.zero,
48+
}) {
49+
return CacheSettings._internal(
50+
storage:
51+
storage ?? (kIsWeb ? CacheStorage.memory : CacheStorage.persistent),
52+
maxSizeBytes: maxSizeBytes ?? (kIsWeb ? 40000000 : 100000000),
53+
maxAge: maxAge,
54+
);
55+
}
4056
}
4157

4258
/// Enum to control the fetch policy for a query

packages/firebase_data_connect/firebase_data_connect/lib/src/firebase_data_connect.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class FirebaseDataConnect extends FirebasePluginPlatform {
179179
FirebaseAppCheck? appCheck,
180180
CallerSDKType? sdkType,
181181
required ConnectorConfig connectorConfig,
182-
CacheSettings? cacheSettings = const CacheSettings()}) {
182+
CacheSettings? cacheSettings}) {
183183
app ??= Firebase.app();
184184
auth ??= FirebaseAuth.instanceFor(app: app);
185185
appCheck ??= FirebaseAppCheck.instanceFor(app: app);
@@ -190,6 +190,9 @@ class FirebaseDataConnect extends FirebasePluginPlatform {
190190
return cachedInstances[app.name]![connectorConfig.toJson()]!;
191191
}
192192

193+
//TODO remove after testing since CS should be null by default
194+
cacheSettings = cacheSettings ?? CacheSettings();
195+
193196
FirebaseDataConnect newInstance = FirebaseDataConnect(
194197
app: app,
195198
auth: auth,

0 commit comments

Comments
 (0)