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 {
    options.extra ??= {};
  }
  options.extra!.addAll({dioCacheTryCache: true});
  if (null != maxAge) {
    options.extra!.addAll({dioCacheKeyMaxAge: maxAge});
  }
  if (null != maxStale) {
    options.extra!.addAll({dioCacheKeyMaxStale: maxStale});
  }
  if (null != primaryKey) {
    options.extra!.addAll({dioCacheKeyPrimaryKey: primaryKey});
  }
  if (null != subKey) {
    options.extra!.addAll({dioCacheKeySubKey: subKey});
  }
  if (null != forceRefresh) {
    options.extra!.addAll({dioCacheKeyForceRefresh: forceRefresh});
  }
  return options;
}