2424/** Settings used to configure a {@link FirebaseFirestore} instance. */
2525public final class FirebaseFirestoreSettings {
2626 /**
27- * Constant to use with
28- * {@link FirebaseFirestoreSettings.Builder#setCacheSizeBytes(long)} to
27+ * Constant to use with {@link FirebaseFirestoreSettings.Builder#setCacheSizeBytes(long)} to
2928 * disable garbage collection.
3029 */
3130 public static final long CACHE_SIZE_UNLIMITED = -1 ;
@@ -42,7 +41,6 @@ public static final class Builder {
4241 private boolean sslEnabled ;
4342 private boolean persistenceEnabled ;
4443
45- private boolean memoryLruGcEnabled ;
4644 private long cacheSizeBytes ;
4745 private LocalCacheSettings cacheSettings ;
4846
@@ -53,13 +51,11 @@ public Builder() {
5351 host = DEFAULT_HOST ;
5452 sslEnabled = true ;
5553 persistenceEnabled = true ;
56- memoryLruGcEnabled = false ;
5754 cacheSizeBytes = DEFAULT_CACHE_SIZE_BYTES ;
5855 }
5956
6057 /**
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
6359 * FirebaseFirestoreSettings} object.
6460 */
6561 public Builder (@ NonNull FirebaseFirestoreSettings settings ) {
@@ -105,16 +101,13 @@ public Builder setSslEnabled(boolean value) {
105101 }
106102
107103 /**
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.
110105 *
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>.
114108 * @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.
118111 */
119112 @ NonNull
120113 @ Deprecated
@@ -128,32 +121,19 @@ public Builder setPersistenceEnabled(boolean value) {
128121 return this ;
129122 }
130123
131- @ NonNull
132- public Builder setMemoryLruGcEnabled (boolean value ) {
133- this .memoryLruGcEnabled = value ;
134- return this ;
135- }
136-
137124 /**
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
144128 * given size, cleanup will be attempted.
145129 *
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.
149131 *
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}.
153134 * @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.
157137 */
158138 @ NonNull
159139 @ Deprecated
@@ -172,24 +152,18 @@ public Builder setCacheSizeBytes(long value) {
172152 }
173153
174154 /**
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}
177156 * and {@link MemoryCacheSettings}, each with different configuration options.
178157 *
179- * <p>
180- * When unspecified, {@link PersistentCacheSettings} will be used by default.
158+ * <p>When unspecified, {@link PersistentCacheSettings} will be used by default.
181159 *
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
188163 * cache size.
189164 *
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}.
193167 */
194168 @ NonNull
195169 public Builder setLocalCacheSettings (@ NonNull LocalCacheSettings settings ) {
@@ -221,11 +195,9 @@ public boolean isSslEnabled() {
221195 }
222196
223197 /**
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.
229201 */
230202 @ Deprecated
231203 public boolean isPersistenceEnabled () {
@@ -234,9 +206,8 @@ public boolean isPersistenceEnabled() {
234206
235207 /**
236208 * @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.
240211 */
241212 @ Deprecated
242213 public long getCacheSizeBytes () {
@@ -256,15 +227,11 @@ public FirebaseFirestoreSettings build() {
256227 private final String host ;
257228 private final boolean sslEnabled ;
258229 private final boolean persistenceEnabled ;
259- private final boolean memoryLruGcEnabled ;
260230 private final long cacheSizeBytes ;
261231
262232 private LocalCacheSettings cacheSettings ;
263233
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. */
268235 private FirebaseFirestoreSettings (Builder builder ) {
269236 host = builder .host ;
270237 sslEnabled = builder .sslEnabled ;
@@ -275,21 +242,15 @@ private FirebaseFirestoreSettings(Builder builder) {
275242
276243 @ Override
277244 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 ;
282247
283248 FirebaseFirestoreSettings that = (FirebaseFirestoreSettings ) o ;
284249
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 ;
293254 return Objects .equals (cacheSettings , that .cacheSettings );
294255 }
295256
@@ -307,18 +268,19 @@ public int hashCode() {
307268 @ NonNull
308269 public String toString () {
309270 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 () + "}" ;
322284 }
323285
324286 /** Returns the host of the Cloud Firestore backend. */
@@ -346,13 +308,8 @@ public boolean isPersistenceEnabled() {
346308 return persistenceEnabled ;
347309 }
348310
349- public boolean isMemoryLruGcEnabled () {
350- return memoryLruGcEnabled ;
351- }
352-
353311 /**
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
356313 * recently used documents.
357314 *
358315 * @deprecated Use {@link FirebaseFirestoreSettings#getCacheSettings()} instead.
@@ -363,6 +320,12 @@ public long getCacheSizeBytes() {
363320 if (cacheSettings instanceof PersistentCacheSettings ) {
364321 return ((PersistentCacheSettings ) cacheSettings ).getSizeBytes ();
365322 } else {
323+ MemoryCacheSettings memorySettings = (MemoryCacheSettings ) cacheSettings ;
324+ if (memorySettings .getGarbageCollectorSettings () instanceof MemoryLruGcSettings ) {
325+ return ((MemoryLruGcSettings ) memorySettings .getGarbageCollectorSettings ())
326+ .getSizeBytes ();
327+ }
328+
366329 return CACHE_SIZE_UNLIMITED ;
367330 }
368331 }
@@ -371,8 +334,7 @@ public long getCacheSizeBytes() {
371334 }
372335
373336 /**
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
376338 * which case a default {@link PersistentCacheSettings} instance is used.
377339 */
378340 @ Nullable
0 commit comments