databasePersistence function

DatabasePersistence databasePersistence({
  1. required PersistenceStorageEngineOpener opener,
  2. int? cacheSizeBytes,
  3. bool cacheServerData = true,
})

Makes the persistence option of an engine package: the client opens the engine with opener and prunes the server cache above cacheSizeBytes (null: 10 MiB).

With cacheServerData false only the pending writes are stored: they survive a restart and are sent again, but no server data is kept, so after a restart a listener waits for the server as it does without persistence. cacheSizeBytes then has nothing to prune.

Throws an ArgumentError when cacheSizeBytes is below 1 MiB or above 100 MiB. Android: core/DatabaseConfig.java:162-171 (DatabaseException there).

Implementation

DatabasePersistence databasePersistence({
  required PersistenceStorageEngineOpener opener,
  int? cacheSizeBytes,
  bool cacheServerData = true,
}) {
  final int size = cacheSizeBytes ?? defaultPersistenceCacheSizeBytes;
  if (size < minPersistenceCacheSizeBytes) {
    throw ArgumentError.value(
      cacheSizeBytes,
      'cacheSizeBytes',
      'The minimum cache size must be at least 1 MiB.',
    );
  }
  if (size > maxPersistenceCacheSizeBytes) {
    throw ArgumentError.value(
      cacheSizeBytes,
      'cacheSizeBytes',
      'The maximum cache size must be at most 100 MiB.',
    );
  }
  return DatabasePersistence._(opener, size, cacheServerData);
}