onResponse method
Called when the response is about to be resolved.
Implementation
@override
void onResponse(Response response, ResponseInterceptorHandler handler) async {
var options = response.requestOptions;
// 获取缓存模式
CacheMode cacheMode = _getCacheMode(options);
if (CacheMode.ONLY_NETWORK == cacheMode) {
// 如果缓存模式是只走网络则不保存缓存
return super.onResponse(response, handler);
}
// 如果缓存模式是优先缓存,则先校验缓存
await CacheManager.getInstance().putCacheWithResp(
response,
cacheConfig.defaultCacheTime,
);
return super.onResponse(response, handler);
}