buildConfigurableCacheOptions function
Options
buildConfigurableCacheOptions({})
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;
}