BuiltInMapCachingProvider.getOrCreateInstance constructor

BuiltInMapCachingProvider.getOrCreateInstance({
  1. String? cacheDirectory,
  2. int? maxCacheSize = 1_000_000_000,
  3. String tileKeyGenerator(
    1. String url
    )?,
  4. Duration? overrideFreshAge,
  5. bool readOnly = false,
})

If an instance exists, return it, otherwise create a new instance

The provided configuration will only be respected if an instance does not already exist.

See individual properties for more information about configuration.

Implementation

factory BuiltInMapCachingProvider.getOrCreateInstance({
  /// Path to the directory to use to store cached tiles & other related files
  ///
  /// The provider actually uses the 'fm_cache' directory created as a child
  /// of the path specified here.
  ///
  /// The program must have rights/permissions to access the path.
  ///
  /// The path does not have to exist, it will be recursively created if
  /// missing.
  ///
  /// All files and directories within the path will be liable to deletion by
  /// the size reducer.
  ///
  /// Defaults to a platform provided cache directory, which may be cleared by
  /// the OS at any time.
  String? cacheDirectory,

  /// Maximum total size of cached tiles, in bytes
  ///
  /// This is applied only when the instance is created, by running the size
  /// reducer. This runs in the background (and so does not delay reads or
  /// writes). The cache size may exceed this limit while the program is
  /// running.
  ///
  /// Disabling the size limit may improve write performance.
  ///
  /// Defaults to 1 GB. Set to `null` to disable.
  int? maxCacheSize = 1_000_000_000,

  /// Function to convert a tile's URL to a key used to uniquely identify the
  /// tile
  ///
  /// Where parts of the URL are volatile or do not represent the tile's
  /// contents/image - for example, API keys contained with the query
  /// parameters - this should be modified to remove the volatile portions.
  ///
  /// Keys must be usable as filenames on all intended platform filesystems.
  /// The callback should not throw.
  ///
  /// Defaults to using [uuidTileKeyGenerator], which custom implementations
  /// may utilise.
  String Function(String url)? tileKeyGenerator,

  /// Override the duration of time a tile is considered fresh for
  ///
  /// Defaults to `null`: use duration calculated from each tile's HTTP
  /// headers.
  Duration? overrideFreshAge,

  /// Prevent any tiles from being added or updated
  ///
  /// Does not disable the size reducer if the cache size is larger than
  /// `maxCacheSize`.
  ///
  /// Defaults to `false`.
  bool readOnly = false,
}) {
  assert(
    maxCacheSize == null || maxCacheSize > 0,
    '`maxCacheSize` must be greater than 0 or disabled',
  );
  assert(
    overrideFreshAge == null || overrideFreshAge > Duration.zero,
    '`overrideFreshAge` must be greater than 0 or disabled',
  );
  return _instance ??= BuiltInMapCachingProviderImpl.create(
    cacheDirectory: cacheDirectory,
    maxCacheSize: maxCacheSize,
    overrideFreshAge: overrideFreshAge,
    tileKeyGenerator: tileKeyGenerator ?? uuidTileKeyGenerator,
    readOnly: readOnly,
    resetSingleton: () => _instance = null,
  );
}