buildConfigurableCacheOptions function

Options buildConfigurableCacheOptions(
  1. {Options? options,
  2. Duration? maxAge,
  3. Duration? maxStale,
  4. String? primaryKey,
  5. String? subKey,
  6. bool? forceRefresh}
)

if null==maxAge, will try to get maxAge and maxStale from response headers. local settings will always overview the value get from service.

Implementation

Options buildConfigurableCacheOptions(
    {Options? options,
    Duration? maxAge,
    Duration? maxStale,
    String? primaryKey,
    String? subKey,
    bool? forceRefresh}) {
  if (null == options) {
    options = Options();
    options.extra = {};
  } else if (options.responseType == ResponseType.stream) {
    throw Exception("ResponseType.stream is not supported");
  } else if (options.extra == null) {
    options.extra = {};
  }
  options.extra!.addAll({DIO_CACHE_KEY_TRY_CACHE: true});
  if (null != maxAge) {
    options.extra!.addAll({DIO_CACHE_KEY_MAX_AGE: maxAge});
  }
  if (null != maxStale) {
    options.extra!.addAll({DIO_CACHE_KEY_MAX_STALE: maxStale});
  }
  if (null != primaryKey) {
    options.extra!.addAll({DIO_CACHE_KEY_PRIMARY_KEY: primaryKey});
  }
  if (null != subKey) {
    options.extra!.addAll({DIO_CACHE_KEY_SUB_KEY: subKey});
  }
  if (null != forceRefresh) {
    options.extra!.addAll({DIO_CACHE_KEY_FORCE_REFRESH: forceRefresh});
  }
  return options;
}