24
24
/** Settings used to configure a {@link FirebaseFirestore} instance. */
25
25
public final class FirebaseFirestoreSettings {
26
26
/**
27
- * Constant to use with
28
- * {@link FirebaseFirestoreSettings.Builder#setCacheSizeBytes(long)} to
27
+ * Constant to use with {@link FirebaseFirestoreSettings.Builder#setCacheSizeBytes(long)} to
29
28
* disable garbage collection.
30
29
*/
31
30
public static final long CACHE_SIZE_UNLIMITED = -1 ;
@@ -42,7 +41,6 @@ public static final class Builder {
42
41
private boolean sslEnabled ;
43
42
private boolean persistenceEnabled ;
44
43
45
- private boolean memoryLruGcEnabled ;
46
44
private long cacheSizeBytes ;
47
45
private LocalCacheSettings cacheSettings ;
48
46
@@ -53,13 +51,11 @@ public Builder() {
53
51
host = DEFAULT_HOST ;
54
52
sslEnabled = true ;
55
53
persistenceEnabled = true ;
56
- memoryLruGcEnabled = false ;
57
54
cacheSizeBytes = DEFAULT_CACHE_SIZE_BYTES ;
58
55
}
59
56
60
57
/**
61
- * Constructs a new {@code FirebaseFirestoreSettings} Builder based on an
62
- * existing {@code
58
+ * Constructs a new {@code FirebaseFirestoreSettings} Builder based on an existing {@code
63
59
* FirebaseFirestoreSettings} object.
64
60
*/
65
61
public Builder (@ NonNull FirebaseFirestoreSettings settings ) {
@@ -105,16 +101,13 @@ public Builder setSslEnabled(boolean value) {
105
101
}
106
102
107
103
/**
108
- * Enables or disables local persistent storage. The default is to use local
109
- * persistent storage.
104
+ * Enables or disables local persistent storage. The default is to use local persistent storage.
110
105
*
111
- * @return A settings object that uses local persistent storage as specified by
112
- * the given
113
- * <tt>value</tt>.
106
+ * @return A settings object that uses local persistent storage as specified by the given
107
+ * <tt>value</tt>.
114
108
* @deprecated Use {@link
115
- * FirebaseFirestoreSettings.Builder#setLocalCacheSettings(LocalCacheSettings)}
116
- * to configure
117
- * SDK cache instead.
109
+ * FirebaseFirestoreSettings.Builder#setLocalCacheSettings(LocalCacheSettings)} to configure
110
+ * SDK cache instead.
118
111
*/
119
112
@ NonNull
120
113
@ Deprecated
@@ -128,32 +121,19 @@ public Builder setPersistenceEnabled(boolean value) {
128
121
return this ;
129
122
}
130
123
131
- @ NonNull
132
- public Builder setMemoryLruGcEnabled (boolean value ) {
133
- this .memoryLruGcEnabled = value ;
134
- return this ;
135
- }
136
-
137
124
/**
138
- * Sets an approximate cache size threshold for the on-disk data. If the cache
139
- * grows beyond this
140
- * size, Cloud Firestore will start removing data that hasn't been recently
141
- * used. The size is
142
- * not a guarantee that the cache will stay below that size, only that if the
143
- * cache exceeds the
125
+ * Sets an approximate cache size threshold for the on-disk data. If the cache grows beyond this
126
+ * size, Cloud Firestore will start removing data that hasn't been recently used. The size is
127
+ * not a guarantee that the cache will stay below that size, only that if the cache exceeds the
144
128
* given size, cleanup will be attempted.
145
129
*
146
- * <p>
147
- * By default, collection is enabled with a cache size of 100 MB. The minimum
148
- * value is 1 MB.
130
+ * <p>By default, collection is enabled with a cache size of 100 MB. The minimum value is 1 MB.
149
131
*
150
- * @return A settings object on which the cache size is configured as specified
151
- * by the given
152
- * {@code value}.
132
+ * @return A settings object on which the cache size is configured as specified by the given
133
+ * {@code value}.
153
134
* @deprecated Use {@link
154
- * FirebaseFirestoreSettings.Builder#setLocalCacheSettings(LocalCacheSettings)}
155
- * to configure
156
- * SDK cache instead.
135
+ * FirebaseFirestoreSettings.Builder#setLocalCacheSettings(LocalCacheSettings)} to configure
136
+ * SDK cache instead.
157
137
*/
158
138
@ NonNull
159
139
@ Deprecated
@@ -172,24 +152,18 @@ public Builder setCacheSizeBytes(long value) {
172
152
}
173
153
174
154
/**
175
- * Specifies the cache used by the SDK. Available options are
176
- * {@link PersistentCacheSettings}
155
+ * Specifies the cache used by the SDK. Available options are {@link PersistentCacheSettings}
177
156
* and {@link MemoryCacheSettings}, each with different configuration options.
178
157
*
179
- * <p>
180
- * When unspecified, {@link PersistentCacheSettings} will be used by default.
158
+ * <p>When unspecified, {@link PersistentCacheSettings} will be used by default.
181
159
*
182
- * <p>
183
- * NOTE: Calling this setter and {@code setPersistenceEnabled()} or @{code
184
- * setCacheSizeBytes()} at the same time will throw an exception during SDK
185
- * initialization.
186
- * Instead, use the configuration in the {@link PersistentCacheSettings} object
187
- * to specify the
160
+ * <p>NOTE: Calling this setter and {@code setPersistenceEnabled()} or @{code
161
+ * setCacheSizeBytes()} at the same time will throw an exception during SDK initialization.
162
+ * Instead, use the configuration in the {@link PersistentCacheSettings} object to specify the
188
163
* cache size.
189
164
*
190
- * @return A settings object on which the cache settings is configured as
191
- * specified by the given
192
- * {@code settings}.
165
+ * @return A settings object on which the cache settings is configured as specified by the given
166
+ * {@code settings}.
193
167
*/
194
168
@ NonNull
195
169
public Builder setLocalCacheSettings (@ NonNull LocalCacheSettings settings ) {
@@ -221,11 +195,9 @@ public boolean isSslEnabled() {
221
195
}
222
196
223
197
/**
224
- * @return boolean indicating whether local persistent storage is enabled or
225
- * not.
226
- * @deprecated Build the {@code FirebaseFirestoreSettings} instance to check
227
- * cache
228
- * configurations.
198
+ * @return boolean indicating whether local persistent storage is enabled or not.
199
+ * @deprecated Build the {@code FirebaseFirestoreSettings} instance to check cache
200
+ * configurations.
229
201
*/
230
202
@ Deprecated
231
203
public boolean isPersistenceEnabled () {
@@ -234,9 +206,8 @@ public boolean isPersistenceEnabled() {
234
206
235
207
/**
236
208
* @return cache size for on-disk data.
237
- * @deprecated Build the {@code FirebaseFirestoreSettings} instance to check
238
- * cache
239
- * configurations.
209
+ * @deprecated Build the {@code FirebaseFirestoreSettings} instance to check cache
210
+ * configurations.
240
211
*/
241
212
@ Deprecated
242
213
public long getCacheSizeBytes () {
@@ -256,15 +227,11 @@ public FirebaseFirestoreSettings build() {
256
227
private final String host ;
257
228
private final boolean sslEnabled ;
258
229
private final boolean persistenceEnabled ;
259
- private final boolean memoryLruGcEnabled ;
260
230
private final long cacheSizeBytes ;
261
231
262
232
private LocalCacheSettings cacheSettings ;
263
233
264
- /**
265
- * Constructs a {@code FirebaseFirestoreSettings} object based on the values in
266
- * the Builder.
267
- */
234
+ /** Constructs a {@code FirebaseFirestoreSettings} object based on the values in the Builder. */
268
235
private FirebaseFirestoreSettings (Builder builder ) {
269
236
host = builder .host ;
270
237
sslEnabled = builder .sslEnabled ;
@@ -275,21 +242,15 @@ private FirebaseFirestoreSettings(Builder builder) {
275
242
276
243
@ Override
277
244
public boolean equals (Object o ) {
278
- if (this == o )
279
- return true ;
280
- if (o == null || getClass () != o .getClass ())
281
- return false ;
245
+ if (this == o ) return true ;
246
+ if (o == null || getClass () != o .getClass ()) return false ;
282
247
283
248
FirebaseFirestoreSettings that = (FirebaseFirestoreSettings ) o ;
284
249
285
- if (sslEnabled != that .sslEnabled )
286
- return false ;
287
- if (persistenceEnabled != that .persistenceEnabled )
288
- return false ;
289
- if (cacheSizeBytes != that .cacheSizeBytes )
290
- return false ;
291
- if (!host .equals (that .host ))
292
- return false ;
250
+ if (sslEnabled != that .sslEnabled ) return false ;
251
+ if (persistenceEnabled != that .persistenceEnabled ) return false ;
252
+ if (cacheSizeBytes != that .cacheSizeBytes ) return false ;
253
+ if (!host .equals (that .host )) return false ;
293
254
return Objects .equals (cacheSettings , that .cacheSettings );
294
255
}
295
256
@@ -307,18 +268,19 @@ public int hashCode() {
307
268
@ NonNull
308
269
public String toString () {
309
270
return "FirebaseFirestoreSettings{"
310
- + "host="
311
- + host
312
- + ", sslEnabled="
313
- + sslEnabled
314
- + ", persistenceEnabled="
315
- + persistenceEnabled
316
- + ", cacheSizeBytes="
317
- + cacheSizeBytes
318
- + ", cacheSettings="
319
- + cacheSettings == null
320
- ? "null"
321
- : cacheSettings .toString () + "}" ;
271
+ + "host="
272
+ + host
273
+ + ", sslEnabled="
274
+ + sslEnabled
275
+ + ", persistenceEnabled="
276
+ + persistenceEnabled
277
+ + ", cacheSizeBytes="
278
+ + cacheSizeBytes
279
+ + ", cacheSettings="
280
+ + cacheSettings
281
+ == null
282
+ ? "null"
283
+ : cacheSettings .toString () + "}" ;
322
284
}
323
285
324
286
/** Returns the host of the Cloud Firestore backend. */
@@ -346,13 +308,8 @@ public boolean isPersistenceEnabled() {
346
308
return persistenceEnabled ;
347
309
}
348
310
349
- public boolean isMemoryLruGcEnabled () {
350
- return memoryLruGcEnabled ;
351
- }
352
-
353
311
/**
354
- * Returns the threshold for the cache size above which the SDK will attempt to
355
- * collect the least
312
+ * Returns the threshold for the cache size above which the SDK will attempt to collect the least
356
313
* recently used documents.
357
314
*
358
315
* @deprecated Use {@link FirebaseFirestoreSettings#getCacheSettings()} instead.
@@ -363,6 +320,12 @@ public long getCacheSizeBytes() {
363
320
if (cacheSettings instanceof PersistentCacheSettings ) {
364
321
return ((PersistentCacheSettings ) cacheSettings ).getSizeBytes ();
365
322
} else {
323
+ MemoryCacheSettings memorySettings = (MemoryCacheSettings ) cacheSettings ;
324
+ if (memorySettings .getGarbageCollectorSettings () instanceof MemoryLruGcSettings ) {
325
+ return ((MemoryLruGcSettings ) memorySettings .getGarbageCollectorSettings ())
326
+ .getSizeBytes ();
327
+ }
328
+
366
329
return CACHE_SIZE_UNLIMITED ;
367
330
}
368
331
}
@@ -371,8 +334,7 @@ public long getCacheSizeBytes() {
371
334
}
372
335
373
336
/**
374
- * Returns the cache settings configured for the SDK. Returns null if it is not
375
- * configured, in
337
+ * Returns the cache settings configured for the SDK. Returns null if it is not configured, in
376
338
* which case a default {@link PersistentCacheSettings} instance is used.
377
339
*/
378
340
@ Nullable
0 commit comments