Closed pishguy closed 3 years ago
I'm sorry, it's not supported yet. maybe later.
@hurshi Thank you for the great library!
@MahdiPishguy It is working on retrofit also:
Try this:
abstract class MyApis{
factory MyApis(Dio dio, {String baseUrl}) = _MyApis;
@GET("/login")
Future<HttpResponse<PageInformation>> login({@DioOptions() Options options}); //change to named paremeter to make it optional
static MyApis create() {
final dio = Dio();
dio.options.headers['Content-Type'] = 'application/json';
dio.options.receiveTimeout = 60000;
dio.options.connectTimeout = 120000;
//add cache interceptor to DIO
dio.interceptors.add(
DioCacheManager(CacheConfig(baseUrl: apiUrl))
.interceptor);
return _MyApis(dio);
}
}
And then you can add cache option to your api call like so:
//create options
Options cacheOptions = buildCacheOptions(Duration(days: 7), forceRefresh: true);
//and then use it in api call
... login(options: cacheOptions);
And you have working solution for Retrofit!
@danilof thanks so much