Skip to content

Set LRU GC as the default for memory cache. #5823

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class FirestoreTests : BaseTestCase() {
assertThat(isSslEnabled).isEqualTo(settings.isSslEnabled)
assertThat(settings.isPersistenceEnabled).isFalse()
assertThat(settings.cacheSettings)
.isEqualTo(memoryCacheSettings { setGcSettings(memoryEagerGcSettings {}) })
.isEqualTo(memoryCacheSettings { setGcSettings(memoryLruGcSettings {}) })

val otherSettings = firestoreSettings {
this.setLocalCacheSettings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,14 @@ public void testLoadWithDocumentsThatAreAlreadyPulledFromBackend() throws Except

@Test
public void testLoadedDocumentsShouldNotBeGarbageCollectedRightAway() throws Exception {
// This test really only makes sense with memory persistence, as SQLite persistence only ever
// This test really only makes sense with memory eager GC, as LRU GCs
// lazily deletes data
db.setFirestoreSettings(
new FirebaseFirestoreSettings.Builder()
.setLocalCacheSettings(MemoryCacheSettings.newBuilder().build())
.setLocalCacheSettings(
MemoryCacheSettings.newBuilder()
.setGcSettings(MemoryLruGcSettings.newBuilder().build())
.build())
.build());

InputStream bundle = new ByteArrayInputStream(createBundle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
Expand Down Expand Up @@ -1335,8 +1334,8 @@ public void testLegacyCacheConfigForMemoryCache() {

waitFor(instance.document("coll/doc").set(map("foo", "bar")));

assertThrows(
RuntimeException.class, () -> waitFor(instance.document("coll/doc").get(Source.CACHE)));
DocumentSnapshot snap = waitFor(instance.document("coll/doc").get(Source.CACHE));
assertEquals(map("foo", "bar"), snap.getData());
}

@Test
Expand All @@ -1363,8 +1362,8 @@ public void testNewCacheConfigForMemoryCache() {

waitFor(instance.document("coll/doc").set(map("foo", "bar")));

assertThrows(
RuntimeException.class, () -> waitFor(instance.document("coll/doc").get(Source.CACHE)));
DocumentSnapshot snap = waitFor(instance.document("coll/doc").get(Source.CACHE));
assertEquals(map("foo", "bar"), snap.getData());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public MemoryGarbageCollectorSettings getGarbageCollectorSettings() {

/** A Builder for creating {@code MemoryCacheSettings} instance. */
public static class Builder {
private MemoryGarbageCollectorSettings gcSettings = MemoryEagerGcSettings.newBuilder().build();
private MemoryGarbageCollectorSettings gcSettings = MemoryLruGcSettings.newBuilder().build();

private Builder() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ private boolean isMemoryLruGcEnabled(FirebaseFirestoreSettings settings) {
return memorySettings.getGarbageCollectorSettings() instanceof MemoryLruGcSettings;
}

return false;
// Enabled by default.
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void builderConstructorShouldCopyAllValuesFromTheGivenSettings() {
assertEquals(settings2.getHost(), "a.b.c");
assertEquals(settings2.isSslEnabled(), false);
assertEquals(settings2.isPersistenceEnabled(), false);
assertEquals(settings2.getCacheSizeBytes(), FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED);
assertEquals(settings2.getCacheSizeBytes(), FirebaseFirestoreSettings.DEFAULT_CACHE_SIZE_BYTES);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class FirestoreTests : BaseTestCase() {
assertThat(isSslEnabled).isEqualTo(settings.isSslEnabled)
assertThat(settings.isPersistenceEnabled).isFalse()
assertThat(settings.cacheSettings)
.isEqualTo(memoryCacheSettings { setGcSettings(memoryEagerGcSettings {}) })
.isEqualTo(memoryCacheSettings { setGcSettings(memoryLruGcSettings {}) })

val otherSettings = firestoreSettings {
this.setLocalCacheSettings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class FirestoreTests : BaseTestCase() {
assertThat(isSslEnabled).isEqualTo(settings.isSslEnabled)
assertThat(settings.isPersistenceEnabled).isFalse()
assertThat(settings.cacheSettings)
.isEqualTo(memoryCacheSettings { setGcSettings(memoryEagerGcSettings {}) })
.isEqualTo(memoryCacheSettings { setGcSettings(memoryLruGcSettings {}) })

val otherSettings = firestoreSettings {
this.setLocalCacheSettings(
Expand Down