Skip to content

Fix return type of Builder.set #5161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 17, 2023
Merged
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
2 changes: 1 addition & 1 deletion firebase-firestore/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ package com.google.firebase.firestore {

public static class MemoryLruGcSettings.Builder {
method @NonNull public com.google.firebase.firestore.MemoryLruGcSettings build();
method public void setSizeBytes(long);
method @NonNull public com.google.firebase.firestore.MemoryLruGcSettings.Builder setSizeBytes(long);
}

public enum MetadataChanges {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* Configures the SDK to use an eager garbage collector for memory cache. The eager garbage
* collector will attempt to remove any documents from SDK's memory cache as soon as it is no longer
* used.
*
* <p>This is the default garbage collector unless specified explicitly otherwise.
*
* <p>To use, create an instance using {@code MemoryEagerGcSettings#newBuilder().build()}, then set
* the instance to {@code MemoryCacheSettings.Builder#setGcSettings}, and use the built {@code
* MemoryCacheSettings} instance to configure the Firestore SDK.
*/
public final class MemoryEagerGcSettings implements MemoryGarbageCollectorSettings {
private MemoryEagerGcSettings() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@

import androidx.annotation.NonNull;

/**
* Configures the SDK to use a Least-Recently-Used garbage collector for memory cache.
*
* <p>To use, create an instance using {@code MemoryLruGcSettings#newBuilder().build()}, then set
* the instance to {@code MemoryCacheSettings.Builder#setGcSettings}, and use the built {@code
* MemoryCacheSettings} instance to configure the Firestore SDK.
*/
public final class MemoryLruGcSettings implements MemoryGarbageCollectorSettings {

private long sizeBytes;
Expand All @@ -30,20 +37,43 @@ public MemoryLruGcSettings build() {
return new MemoryLruGcSettings(sizeBytes);
}

public void setSizeBytes(long size) {
/**
* Sets an approximate cache size threshold for the memory cache. If the cache grows beyond this
* size, Firestore SDK will start removing data that hasn't been recently used. The size is not
* a guarantee that the cache will stay below that size, only that if the cache exceeds the
* given size, cleanup will be attempted.
*
* <p>A default size of 100MB (100 * 1024 * 1024) is used if unset. The minimum value to set is
* 1 MB (1024 * 1024).
*
* @return this {@code Builder} instance.
*/
@NonNull
public Builder setSizeBytes(long size) {
sizeBytes = size;
return this;
}
}

private MemoryLruGcSettings(long size) {
sizeBytes = size;
}

/** Returns a new instance of {@link MemoryLruGcSettings.Builder} with default configurations. */
@NonNull
public static MemoryLruGcSettings.Builder newBuilder() {
return new Builder();
}

/**
* Returns cache size threshold for the memory cache. If the cache grows beyond this size,
* Firestore SDK will start removing data that hasn't been recently used. The size is not a
* guarantee that the cache will stay below that size, only that if the cache exceeds the given
* size, cleanup will be attempted.
*
* <p>By default, memory LRU cache is enabled with a cache size of 100MB (100 * 1024 * 1024). The
* minimum value is 1 MB (1024 * 1024).
*/
public long getSizeBytes() {
return sizeBytes;
}
Expand Down