Skip to content

Commit 341251c

Browse files
committed
Make memory lru gc the default
1 parent c6ecac8 commit 341251c

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

packages/firestore/src/api/cache_config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ class MemoryLocalCacheImpl implements MemoryLocalCache {
6262
this._offlineComponentProvider =
6363
settings.garbageCollector._offlineComponentProvider;
6464
} else {
65-
this._offlineComponentProvider = new MemoryOfflineComponentProvider();
65+
this._offlineComponentProvider = new LruGcMemoryOfflineComponentProvider(
66+
undefined
67+
);
6668
}
6769
}
6870

packages/firestore/src/core/firestore_client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import { Aggregate } from './aggregate';
6464
import { NamedQuery } from './bundle';
6565
import {
6666
ComponentConfiguration,
67+
LruGcMemoryOfflineComponentProvider,
6768
MemoryOfflineComponentProvider,
6869
OfflineComponentProvider,
6970
OnlineComponentProvider
@@ -339,7 +340,7 @@ async function ensureOfflineComponents(
339340
logDebug(LOG_TAG, 'Using default OfflineComponentProvider');
340341
await setOfflineComponentProvider(
341342
client,
342-
new MemoryOfflineComponentProvider()
343+
new LruGcMemoryOfflineComponentProvider(undefined)
343344
);
344345
}
345346
}

packages/firestore/test/integration/util/helpers.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,51 @@ export function withTestDb(
254254
});
255255
}
256256

257+
export function withEnsuredEagerGcTestDb(
258+
fn: (db: Firestore) => Promise<void>
259+
): Promise<void> {
260+
const newSettings = { ...DEFAULT_SETTINGS };
261+
newSettings.localCache = memoryLocalCache({
262+
garbageCollector: memoryEagerGarbageCollector()
263+
});
264+
return withTestDbsSettings(
265+
false,
266+
DEFAULT_PROJECT_ID,
267+
newSettings,
268+
1,
269+
async ([db]) => {
270+
return fn(db);
271+
}
272+
);
273+
}
274+
275+
export function withEnsuredLruGcTestDb(
276+
persistence: boolean,
277+
fn: (db: Firestore) => Promise<void>
278+
): Promise<void> {
279+
const newSettings = { ...DEFAULT_SETTINGS };
280+
if (persistence) {
281+
newSettings.localCache = persistentLocalCache({
282+
cacheSizeBytes: 1 * 1024 * 1024
283+
});
284+
} else {
285+
newSettings.localCache = memoryLocalCache({
286+
garbageCollector: memoryLruGarbageCollector({
287+
cacheSizeBytes: 1 * 1024 * 1024
288+
})
289+
});
290+
}
291+
return withTestDbsSettings(
292+
persistence,
293+
DEFAULT_PROJECT_ID,
294+
newSettings,
295+
1,
296+
async ([db]) => {
297+
return fn(db);
298+
}
299+
);
300+
}
301+
257302
/** Runs provided fn with a db for an alternate project id. */
258303
export function withAlternateTestDb(
259304
persistence: PersistenceMode | typeof PERSISTENCE_MODE_UNSPECIFIED,

0 commit comments

Comments
 (0)