Flutter Chopper库缓存HTTP响应

时间:2020-09-07 05:52:59

标签: flutter chopper

在我的移动应用程序中,我正在使用Chopper http库,并且我想用该库缓存http响应,我的服务器返回以下带有响应的标头:

<-- 200 http://www.www.www/api/v1/dashboard/allData
content-type: application/json
cache-control: max-age=600, private
transfer-encoding: chunked
date: Mon, 07 Sep 2020 05:47:00 GMT
server: Apache

我将此拦截器添加到chopper拦截器中:

final client = ChopperClient(

client: http.IOClient(
  HttpClient()..connectionTimeout = const Duration(seconds: 60),
),
baseUrl: webUri,
services: [
  _$WebApi(),
],
converter: const JsonConverter(),
interceptors: [
  const HeadersInterceptor({'Content-Type': 'application/json','Cache-Control':'private, max-age=600'}),
  HttpLoggingInterceptor(),
]);

现在我希望缓存可以很好地运行我的应用程序,此解决方案正确吗?

0 个答案:

没有答案