Skip to content

Commit 60a730e

Browse files
authored
New way to config Firestore SDK Cache. (#7015)
* New way to config Firestore SDK Cache. * fixups * Fix some test failures * Fixing dts file * Add public comments * API report * Create brown-beers-tease.md * warning messages and more tests * Addressing comments * Update API reports * Fix provider test failure for node w/o indexeddb * Fix node memory test * rename cache to localCache * Update API reports * Tech writer review * yarn docgen * auth change * Update API reports * docgen devsite * Fix changeset * Another auth change * more devsite fix * Update API reports * Rename indexeddb to persistent --------- Co-authored-by: wu-hui <[email protected]>
1 parent 9a21a57 commit 60a730e

23 files changed

+992
-98
lines changed

.changeset/brown-beers-tease.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/firestore": minor
3+
---
4+
5+
Introduces a new way to config Firestore SDK Cache.

common/api-review/firestore.api.md

+56-2
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ export class DocumentSnapshot<T = DocumentData> {
163163

164164
export { EmulatorMockTokenOptions }
165165

166-
// @public
166+
// @public @deprecated
167167
export function enableIndexedDbPersistence(firestore: Firestore, persistenceSettings?: PersistenceSettings): Promise<void>;
168168

169-
// @public
169+
// @public @deprecated
170170
export function enableMultiTabIndexedDbPersistence(firestore: Firestore): Promise<void>;
171171

172172
// @public
@@ -219,13 +219,17 @@ export class FirestoreError extends FirebaseError {
219219
// @public
220220
export type FirestoreErrorCode = 'cancelled' | 'unknown' | 'invalid-argument' | 'deadline-exceeded' | 'not-found' | 'already-exists' | 'permission-denied' | 'resource-exhausted' | 'failed-precondition' | 'aborted' | 'out-of-range' | 'unimplemented' | 'internal' | 'unavailable' | 'data-loss' | 'unauthenticated';
221221

222+
// @public
223+
export type FirestoreLocalCache = MemoryLocalCache | PersistentLocalCache;
224+
222225
// @public
223226
export interface FirestoreSettings {
224227
cacheSizeBytes?: number;
225228
experimentalAutoDetectLongPolling?: boolean;
226229
experimentalForceLongPolling?: boolean;
227230
host?: string;
228231
ignoreUndefinedProperties?: boolean;
232+
localCache?: FirestoreLocalCache;
229233
ssl?: boolean;
230234
}
231235

@@ -327,6 +331,15 @@ export interface LoadBundleTaskProgress {
327331

328332
export { LogLevel }
329333

334+
// @public
335+
export interface MemoryLocalCache {
336+
// (undocumented)
337+
kind: 'memory';
338+
}
339+
340+
// @public
341+
export function memoryLocalCache(): MemoryLocalCache;
342+
330343
// @public
331344
export function namedQuery(firestore: Firestore, name: string): Promise<Query | null>;
332345

@@ -404,6 +417,47 @@ export interface PersistenceSettings {
404417
forceOwnership?: boolean;
405418
}
406419

420+
// @public
421+
export interface PersistentCacheSettings {
422+
cacheSizeBytes?: number;
423+
tabManager?: PersistentTabManager;
424+
}
425+
426+
// @public
427+
export interface PersistentLocalCache {
428+
// (undocumented)
429+
kind: 'persistent';
430+
}
431+
432+
// @public
433+
export function persistentLocalCache(settings?: PersistentCacheSettings): PersistentLocalCache;
434+
435+
// @public
436+
export interface PersistentMultipleTabManager {
437+
// (undocumented)
438+
kind: 'PersistentMultipleTab';
439+
}
440+
441+
// @public
442+
export function persistentMultipleTabManager(): PersistentMultipleTabManager;
443+
444+
// @public
445+
export interface PersistentSingleTabManager {
446+
// (undocumented)
447+
kind: 'persistentSingleTab';
448+
}
449+
450+
// @public
451+
export function persistentSingleTabManager(settings: PersistentSingleTabManagerSettings | undefined): PersistentSingleTabManager;
452+
453+
// @public
454+
export interface PersistentSingleTabManagerSettings {
455+
forceOwnership?: boolean;
456+
}
457+
458+
// @public
459+
export type PersistentTabManager = PersistentSingleTabManager | PersistentMultipleTabManager;
460+
407461
// @public
408462
export type Primitive = string | number | boolean | undefined | null;
409463

docs-devsite/firestore_.firestoresettings.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@ export declare interface FirestoreSettings
2222

2323
| Property | Type | Description |
2424
| --- | --- | --- |
25-
| [cacheSizeBytes](./firestore_.firestoresettings.md#firestoresettingscachesizebytes) | number | An approximate cache size threshold for the on-disk data. If the cache grows beyond this size, Firestore 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.<!-- -->The default value is 40 MB. The threshold must be set to at least 1 MB, and can be set to <code>CACHE_SIZE_UNLIMITED</code> to disable garbage collection. |
25+
| [cacheSizeBytes](./firestore_.firestoresettings.md#firestoresettingscachesizebytes) | number | NOTE: This field will be deprecated in a future major release. Use <code>cache</code> field instead to specify cache size, and other cache configurations.<!-- -->An approximate cache size threshold for the on-disk data. If the cache grows beyond this size, Firestore 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.<!-- -->The default value is 40 MB. The threshold must be set to at least 1 MB, and can be set to <code>CACHE_SIZE_UNLIMITED</code> to disable garbage collection. |
2626
| [experimentalAutoDetectLongPolling](./firestore_.firestoresettings.md#firestoresettingsexperimentalautodetectlongpolling) | boolean | Configures the SDK's underlying transport (WebChannel) to automatically detect if long-polling should be used. This is very similar to <code>experimentalForceLongPolling</code>, but only uses long-polling if required.<!-- -->This setting will likely be enabled by default in future releases and cannot be combined with <code>experimentalForceLongPolling</code>. |
2727
| [experimentalForceLongPolling](./firestore_.firestoresettings.md#firestoresettingsexperimentalforcelongpolling) | boolean | Forces the SDKs underlying network transport (WebChannel) to use long-polling. Each response from the backend will be closed immediately after the backend sends data (by default responses are kept open in case the backend has more data to send). This avoids incompatibility issues with certain proxies, antivirus software, etc. that incorrectly buffer traffic indefinitely. Use of this option will cause some performance degradation though.<!-- -->This setting cannot be used with <code>experimentalAutoDetectLongPolling</code> and may be removed in a future release. If you find yourself using it to work around a specific network reliability issue, please tell us about it in https://github.com/firebase/firebase-js-sdk/issues/1674. |
2828
| [host](./firestore_.firestoresettings.md#firestoresettingshost) | string | The hostname to connect to. |
2929
| [ignoreUndefinedProperties](./firestore_.firestoresettings.md#firestoresettingsignoreundefinedproperties) | boolean | Whether to skip nested properties that are set to <code>undefined</code> during object serialization. If set to <code>true</code>, these properties are skipped and not written to Firestore. If set to <code>false</code> or omitted, the SDK throws an exception when it encounters properties of type <code>undefined</code>. |
30+
| [localCache](./firestore_.firestoresettings.md#firestoresettingslocalcache) | [FirestoreLocalCache](./firestore_.md#firestorelocalcache) | Specifies the cache used by the SDK. Availabe options are <code>MemoryLocalCache</code> and <code>IndexedDbLocalCache</code>, each with different configuration options.<!-- -->When unspecified, <code>MemoryLocalCache</code> will be used by default.<!-- -->NOTE: setting this field and <code>cacheSizeBytes</code> at the same time will throw exception during SDK initialization. Instead, using the configuration in the <code>FirestoreLocalCache</code> object to specify the cache size. |
3031
| [ssl](./firestore_.firestoresettings.md#firestoresettingsssl) | boolean | Whether to use SSL when connecting. |
3132

3233
## FirestoreSettings.cacheSizeBytes
3334

35+
NOTE: This field will be deprecated in a future major release. Use `cache` field instead to specify cache size, and other cache configurations.
36+
3437
An approximate cache size threshold for the on-disk data. If the cache grows beyond this size, Firestore 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.
3538

3639
The default value is 40 MB. The threshold must be set to at least 1 MB, and can be set to `CACHE_SIZE_UNLIMITED` to disable garbage collection.
@@ -85,6 +88,20 @@ Whether to skip nested properties that are set to `undefined` during object seri
8588
ignoreUndefinedProperties?: boolean;
8689
```
8790

91+
## FirestoreSettings.localCache
92+
93+
Specifies the cache used by the SDK. Availabe options are `MemoryLocalCache` and `IndexedDbLocalCache`<!-- -->, each with different configuration options.
94+
95+
When unspecified, `MemoryLocalCache` will be used by default.
96+
97+
NOTE: setting this field and `cacheSizeBytes` at the same time will throw exception during SDK initialization. Instead, using the configuration in the `FirestoreLocalCache` object to specify the cache size.
98+
99+
<b>Signature:</b>
100+
101+
```typescript
102+
localCache?: FirestoreLocalCache;
103+
```
104+
88105
## FirestoreSettings.ssl
89106

90107
Whether to use SSL when connecting.

0 commit comments

Comments
 (0)